java时间格式转换: Sep 29, 2012 1:00:01 AM 如何转换成标准的java Date对象
RT,现在已经确定Date.parse(String)方法可以正常解析,但是这个方法早就过时了,jdk文档里面推荐的是DateFormat.parse方法替换,但是这个方...
RT,现在已经确定Date.parse(String)方法可以正常解析,但是这个方法早就过时了,jdk文档里面推荐的是DateFormat.parse方法替换,但是这个方法无法解析上面这个字符串!求解释啊!在线等答案!
展开
4个回答
展开全部
package test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateParser {
public static void main(String[] args) {
//java时间格式转换: Sep 29, 2012 1:00:01 AM 如何转换成标准的java Date对象
/*
LetterDate or Time ComponentPresentationExamples
GEra designatorTextAD
yYearYear1996; 96
MMonth in yearMonthJuly; Jul; 07
wWeek in yearNumber27
WWeek in monthNumber2
DDay in yearNumber189
dDay in monthNumber10
FDay of week in monthNumber2
EDay in weekTextTuesday; Tue
aAm/pm markerTextPM
HHour in day (0-23)Number0
kHour in day (1-24)Number24
KHour in am/pm (0-11)Number0
hHour in am/pm (1-12)Number12
mMinute in hourNumber30
sSecond in minuteNumber55
SMillisecondNumber978
zTime zoneGeneral time zonePacific Standard Time; PST; GMT-08:00
ZTime zoneRFC 822 time zone-0800
*/
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy K:m:s a",Locale.ENGLISH);
Date d2 = null;
try {
d2 = sdf.parse("Sep 29, 2012 1:00:01 AM");
} catch (ParseException e) {
e.printStackTrace();
}
Date d3 = new Date();
System.out.println("d2 ====== "+d2);
System.out.println("d3 ====== "+sdf.format(d3));
}
}
展开全部
你上面这个到底是什么?String还 Date?建议使用SimpleDateFormat对象来转换
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy K:m:s a",Locale.ENGLISH);
Date d2 = null;
try {
d2 = sdf.parse("Sep 18, 2017 4:17:28 PM");
} catch (ParseException e) {
e.printStackTrace();
}
Date d3 = new Date();
LogUtil.e("d2 ====== "+d2+" "+sdf2.format(d2));
LogUtil.e("d3 ====== "+" "+d3+" "+sdf.format(d3));
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy K:m:s a",Locale.ENGLISH);
Date d2 = null;
try {
d2 = sdf.parse("Sep 18, 2017 4:17:28 PM");
} catch (ParseException e) {
e.printStackTrace();
}
Date d3 = new Date();
LogUtil.e("d2 ====== "+d2+" "+sdf2.format(d2));
LogUtil.e("d3 ====== "+" "+d3+" "+sdf.format(d3));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询