此代码引发“无效格式”或“格式错误”异常:
码:
strDate = "21/10/2015 12:00:00 AM";
format = "dd/MM/yyyy hh:mm:ss a";
DateTime.parse(strDate, DateTimeFormat.forPattern(format)).toDate();
Run Code Online (Sandbox Code Playgroud)
例外:
java.lang.IllegalArgumentException: Invalid format: "21/10/2015 12:00:00 AM"
is malformed at "AM"
Run Code Online (Sandbox Code Playgroud)
怎么了?
我正在使用Joda-Time:2.8.1
(我已经搜索过,并且我认为这是该strDate的正确模式)
如何使用掩码将浮点数格式化为字符串?
(我不擅长正则表达式,但如果有人知道单行解决方案,为什么不呢?)
这是我的问题:
我有一个像"6.88"的浮点数,我需要使用以下掩码"00000000000.00"对其进行格式化
6.88 ="00000000006.88"
14.3 ="00000000014.30"
00.0 ="00000000000.00"
我已经阅读了以下帖子,但我无法理解:
我的数据示例:
6.88 => 00000000006.88
56.62 => 00000000056.62
9.58 => 00000000009.58
24.75 => 00000000024.75
14.30 => 00000000014.30
Run Code Online (Sandbox Code Playgroud)
我的效率不高也不快:
有更简单的方法吗?
我有一个shell脚本的输出,如下所示
output1 ..... 1
output2 ..... 2
output3 ............3
Run Code Online (Sandbox Code Playgroud)
我尝试在脚本内以相等的间距格式化它,但输出仍然没有统一的间距.
我想打印输出如下.
output1 ..... 1
output2 ..... 2
output3 ......3
Run Code Online (Sandbox Code Playgroud)
是否有任何通讯可以完成这项工作.我用bash.
这是代码.
lnode=abc
printf "server name ......... "$lnode""
printf "\nserver uptime and load details : ......... `uptime`"
printf "\n"
lcpu=`cat /proc/cpuinfo | grep -i process |wc -l`
printf "Total number of CPUs on this server : ......... $lcpu\n"
Run Code Online (Sandbox Code Playgroud)
-谢谢.
我知道要将double值转换为string,我可以这样做:
String value = String.format("%f", 10.0000);
Run Code Online (Sandbox Code Playgroud)
我也可以使用这个来控制小数点后的位数:
String value = String.format("%.3f", 10.000000);
Run Code Online (Sandbox Code Playgroud)
但我的问题是,我通过变量接收小数点后的位数.如何使用String.format打印用户提供的小数后的位数.
此致,Anuj
背景
使用UltraEdit,您可以选择正确格式化XML内容的格式:
查看>查看为(突出显示的文件类型)> XML
可以更改颜色,从而更好地读取标签,属性和内容。
然后,您可以执行以下操作:
格式> XML转换为CR / LF
这样就可以适当地使用换行符。
我需要的
我所缺少的是适当的缩进。您可以折叠/展开线段,但是如果没有适当的缩进,很难看到其底层结构。
题
如何对XML内容应用适当的缩进?
如何使用单行代码在VBA Excel中格式化多个单元格范围的数字,对齐,字体,边框,填充,保护等?例如,我有以下代码
With Sheets("Sheet1")
.Columns("A").ColumnWidth = 15
.Columns("C").ColumnWidth = 15
.Columns("G").ColumnWidth = 15
.Range("A:C").Font.Color = vbRed
.Range("G:G").Font.Color = vbRed
End With
Run Code Online (Sandbox Code Playgroud)
我可以这样做(伪代码):
With Sheets("Sheet1")
.Columns("A", "C", "G").ColumnWidth = 15
.Range("A:C", "G:G").Font.Color = vbRed
End With
Run Code Online (Sandbox Code Playgroud)
我认为类似的东西.Columns(Array("A", "C", "G")).ColumnWidth = 15会起作用,但是发生了错误.
我在我的数据库中有一个用户的出生日期,但我希望将其格式化为2000年3月27日.我已经注册了日期,我可以格式化,但如果我尝试格式化它的出生日期给我以下错误: 在字符串上调用成员函数format()
这段代码我用来显示和格式化用户的出生日期:
{{ucfirst(Auth::user()->created_at->format("M d Y"))}}
Run Code Online (Sandbox Code Playgroud)
我尝试将此代码用于出生日期,因为它位于包含所有用户的表中:
{{ucfirst($user->birthdate->format("M d Y"))}}
Run Code Online (Sandbox Code Playgroud)
这是数据库结构:http: //i.stack.imgur.com/Agchg.png
我试图在FORTRAN 77中使用format语句,以便定义我想要读取数字的精度.
以下是我的代码行:
double precision x,y,z
open(u,FILE='points.dat',STATUS='OLD')
do 10 i=1,n
read(u,100) x,y,z
write(*,*),'check', x,y,z
enddo
100 format(3(2x,D14.2))
close(u)
Run Code Online (Sandbox Code Playgroud)
我试着阅读这些数字:1.0542095e-03 -3.4176819e-02 -1.3796906e-01,格式不同,结果如下:
format(3(2x,E14.2)): check 0.0010542095 -0.034176819 -0.13796906
format(3(2x,E14.7)): check 0.0010542095 -0.034176819 -0.13796906
format(3(2x,D14.7)): check 0.0010542095 -0.034176819 -0.13796906
Run Code Online (Sandbox Code Playgroud)
我本来期望第一行给出0.001000000,第二行给出0.001054209,但似乎格式声明对读数没有影响或者我没有正确使用它.任何人都可以向我解释格式在读取功能中的效果以及如何正确使用它?
我想在Python 3.5中看到一个打印输出,{1}但我没有.format正确的语法.我试过了:
print('{{}}'.format('1')) # prints {}
print('{{id}}'.format(id='1')) # prints {id}
print('{{0}}'.format('1')) # prints {0}
print('\{{}\}'.format(1)) # ValueError: Single '}' encountered in format string
Run Code Online (Sandbox Code Playgroud)
什么是正确的print('{}'.format())打印类似的语法{1}?
我正在尝试创建程序,要求用户输入特定格式的序列号,程序将验证代码是否有效.
格式应为2个数字,后跟短划线,4个数字,一个点,然后是4个数字和2个字母(注意:接受的字母只有a,b,c).
有效格式示例:
31-0001.2341ac
00-9999.0001cb
Run Code Online (Sandbox Code Playgroud)
如果字符串的长度比格式(长度为14个字符)更长/更短,则应显示无效.同样的事情,如果使用其他字符,它也会说无效.
这是我到目前为止所做的代码.我不知道如何才能达到指定的格式.希望有人可以帮忙..
import java.util.Scanner;
public class SerialCheck{
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("How many serial numbers would you like to check: ");
int length = sc.nextInt();
int valid = 0;
String[] sSerials = new String[length];
for (int nCtr = 0; nCtr < length; nCtr++){
System.out.print ("Enter Serial " + (nCtr+1) + ": ");
sSerials[nCtr] = sc.next();
}
System.out.println();
System.out.println("The following were added: ");
for(int nCtr = 0; nCtr < …Run Code Online (Sandbox Code Playgroud)