当前位置: 技术问答>java相关
日期表示问题
来源: 互联网 发布时间:2015-05-31
本文导语: GregorianCalendar now=new GregorianCalendar(); int Year=now.get(now.YEAR); int Month=now.get(now.MONTH)+1; int Date=now.get(now.DATE); int Hour=now.get(now.HOUR_OF_DAY); int Minute=now.get(now.MINUTE); int Second=now.get(now.SECOND); 得到的日期为 2002515143...
GregorianCalendar now=new GregorianCalendar();
int Year=now.get(now.YEAR);
int Month=now.get(now.MONTH)+1;
int Date=now.get(now.DATE);
int Hour=now.get(now.HOUR_OF_DAY);
int Minute=now.get(now.MINUTE);
int Second=now.get(now.SECOND);
得到的日期为 20025151430
怎样得到的日期为 200205151430
即时间为1位的表示为2位,有没有现成的方法;
|
java.text.SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss");
String result = formatter.format(date);
String result = formatter.format(date);
|
不好意思!没看到你的year,month,date等都是int!我看你还是写个getStringDate()的方法吧!返回一个String,我像这样会好做些!
private static String getStringDate(GregorianCalendar now) {
String sDate = "";
int Year=now.get(now.YEAR);
int Month=now.get(now.MONTH)+1;
int Date=now.get(now.DATE);
int Hour=now.get(now.HOUR_OF_DAY);
int Minute=now.get(now.MINUTE);
int Second=now.get(now.SECOND);
sDate = String.vauleOf(Year);
if (Month
private static String getStringDate(GregorianCalendar now) {
String sDate = "";
int Year=now.get(now.YEAR);
int Month=now.get(now.MONTH)+1;
int Date=now.get(now.DATE);
int Hour=now.get(now.HOUR_OF_DAY);
int Minute=now.get(now.MINUTE);
int Second=now.get(now.SECOND);
sDate = String.vauleOf(Year);
if (Month