Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 将长日期转换为特定的短日期格式_Date_Datepicker_Long Integer_Short - Fatal编程技术网

Date 将长日期转换为特定的短日期格式

Date 将长日期转换为特定的短日期格式,date,datepicker,long-integer,short,Date,Datepicker,Long Integer,Short,将长日期格式转换为特定的短日期格式 我想从Datepicker(Jcalander)获取日期,将其格式化为dd-mm-yyyy格式并分配给字符串变量。我尝试使用下面显示的代码。但是没有得到我想要的日期格式 SimpleDateFormat simpleFormat = (SimpleDateFormat) jCalendarCombo1.getDateFormat(); Date date = jCalendarCombo1.getDate(); System.out.println(date)

将长日期格式转换为特定的短日期格式

我想从Datepicker(Jcalander)获取日期,将其格式化为dd-mm-yyyy格式并分配给字符串变量。我尝试使用下面显示的代码。但是没有得到我想要的日期格式

SimpleDateFormat simpleFormat = (SimpleDateFormat) jCalendarCombo1.getDateFormat();
Date date = jCalendarCombo1.getDate();
System.out.println(date); // Prints Thu Mar 28 00:00:00 IST 2013


String s = simpleFormat.format(date);
System.out.println(s); // prints Thursday, March 28, 2013

System.out.println("Date SHORT format: "  + DateFormat.getDateInstance(DateFormat.SHORT).format(date));  // prints 3/28/13
如果您想要一个固定的、不依赖于语言环境的格式,您可以自己创建它

SimpleDateFormat shortformat = new SimpleDateFormat("dd-MM-yyyy");
String s = shortformat.format(date);
System.out.println(s);                        // Prints 29-03-2013

谢谢你的快速反应。现在可以了。我以2013年3月29日的格式得到了日期。再来一次。