简体   繁体   English

JXDatePicker返回错误的日期

[英]The JXDatePicker Returns Wrong Date

I am using The JXDatePicker in my Swing Application, and uses the following code to set the Date Value to the SQL Server Table 我在Swing应用程序中使用JXDatePicker,并使用以下代码将日期值设置为SQL Server表

 Date date = jDatePicker1.getDate();          
 String expectedPattern = "yyyy-MM-dd hh:mm:ss.SSS";
 String currentFormat = "dd-MM-yyyy hh:mm:ss.SSS";
 SimpleDateFormat dateFormatReq = new SimpleDateFormat(expectedPattern);
 SimpleDateFormat dateFormatCurr = new SimpleDateFormat(currentFormat);
 String strDate = dateFormatReq.format(dateFormatCurr.parse(dateFormatCurr.format(date)));

The problem is that the strDate value is '2011-04-01 12:00:00.000' 问题是strDate值为'2011-04-01 12:00:00.000'

where as my requirement is '2011-04-01 00:00:00.000' 我的要求是“ 2011-04-01 00:00:00.000”

Any Help in the matter will be highly appreciable. 在这方面的任何帮助将非常可贵。

Use HH instead of hh for hours. 使用HH代替hh数小时。 Because HH is "Hour in day (0-23)" and hh is "Hour in am/pm (1-12)". 因为HH是“一天中的小时(0-23)”,而hh是“上午/小时中的小时(1-12)”。 See http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html . 参见http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM