当前位置: 技术问答>java相关
java中如何得到系统时间
来源: 互联网 发布时间:2015-07-25
本文导语: 格式要像c中的__TIME__和__DATE__ 请以前做过的大哥大嫂们贴一下源代码 | public Date getdate() throws Exception { Date date=null; Calendar MyDate = Calendar.getInstance(); MyDate.setTime(new java.util.D...
格式要像c中的__TIME__和__DATE__
请以前做过的大哥大嫂们贴一下源代码
请以前做过的大哥大嫂们贴一下源代码
|
public Date getdate() throws Exception {
Date date=null;
Calendar MyDate = Calendar.getInstance();
MyDate.setTime(new java.util.Date());
date=MyDate.getTime();
return date;
}
最标准的,也是sun推荐的。
Date date=null;
Calendar MyDate = Calendar.getInstance();
MyDate.setTime(new java.util.Date());
date=MyDate.getTime();
return date;
}
最标准的,也是sun推荐的。
|
currentTimeMillis
public static long currentTimeMillis()Returns the current time in milliseconds.
See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).
Returns:
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
public static long currentTimeMillis()Returns the current time in milliseconds.
See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).
Returns:
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
|
Date date = new Date();
然后自己定格式输出!
然后自己定格式输出!
|
public static String GetTodayStr(String rDateFormat) {
SimpleDateFormat lFormat;
lFormat = new SimpleDateFormat(rDateFormat);
gRtnStr = lFormat.format(new java.util.Date());
return gRtnStr;
}
SimpleDateFormat lFormat;
lFormat = new SimpleDateFormat(rDateFormat);
gRtnStr = lFormat.format(new java.util.Date());
return gRtnStr;
}
|
public String getdate_s() throws Exception {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
Calendar MyDate = Calendar.getInstance();
MyDate.setTime(new java.util.Date());
String adddate=df.format(MyDate.getTime()).substring(0,8);
return adddate;
}
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
Calendar MyDate = Calendar.getInstance();
MyDate.setTime(new java.util.Date());
String adddate=df.format(MyDate.getTime()).substring(0,8);
return adddate;
}