运行此代码时,我得到了意想不到的结果:
var DateFormat_in = new SimpleDateFormat("mm/dd/yyyy HH:mm:ss");
var DateFormat_out = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
var m ="4/29/2016 12:12:12"
println(str_timestamp(m,DateFormat_in,DateFormat_out)) // third
def str_timestamp(date_str:String,format_in:SimpleDateFormat,format_out: SimpleDateFormat): DateTime =
{
val date = format_in.parse(date_str)
val date_modified_str = format_out.format(date)
println(date_modified_str) // first
val temp = format_out.parse(date_modified_str);
println(temp) // second
val dateTime: DateTime = new DateTime(temp.getTime)
dateTime
}
我得到以下内容:
2016-12-29 12:12:12
Fri Jan 29 12:12:12 CET 2016
2016-01-29T12:12:12.000 + 01:00
为什么月份从一个变为一个?如何做到对不对?