本文介绍了解析日期结果错误16小时2分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串07/Dec/2016:07:38:59 1000
.我想将其解析为一个日期.我该怎么做才能成为日期07/Dec/2016 07:38:59 1000
?现在它打印出Wed Dec 07 23:40:59 CET 2016
.
I have a string 07/Dec/2016:07:38:59 1000
.I want to parse it to a date.What do I do to become a date 07/Dec/2016 07:38:59 1000
as a result?Now it prints out Wed Dec 07 23:40:59 CET 2016
.
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeParse {
public static void main(String[] args) throws ParseException {
String time ="07/Dec/2016:07:38:59 1000";
SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy:hh:mm:ss");
String dateString = format.format( new Date() );
Date date = format.parse ( "07/Dec/2016:07:38:59 1000" );
System.out.println(date);
}
}
推荐答案
我假设应该以毫秒为单位1000?如果是这样,那是不正确的.就像写13:60:60
I'm assuming the 1000 is supposed to be milliseconds? if so, it's incorrect. it's like writing 13:60:60
这也意味着您输入的时间字符串格式缺少毫秒值.它应该是"dd/MMM/yyyy:hh:mm:ss SSS"
毫秒值不能超过3位数字
This also means the time string format you entered is missing the milliseconds value.It should be "dd/MMM/yyyy:hh:mm:ss SSS"
milliseconds value should not be more than 3 digits
这篇关于解析日期结果错误16小时2分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!