当前位置:首页 > JSP教程 > JSP常见问题

Java输出系统当前的日期(年月日时分秒毫秒)

复制代码 代码如下:

package test.remote.tools.combine;

import java.text.simpledateformat;
import java.util.calendar;
import java.util.date;
import java.util.gregoriancalendar;

public class testoutdate
{
public static void main(string[] args)
{
//method 1
calendar nowtime = new gregoriancalendar();
string strdatetime="["+string.format("%04d", nowtime.get(calendar.year))+"/"+
string.format("%02d", nowtime.get(calendar.month))+"/" +
string.format("%02d", nowtime.get(calendar.date))+" " +
string.format("%02d", nowtime.get(calendar.hour))+":" +
string.format("%02d", nowtime.get(calendar.minute))+":" +
string.format("%02d", nowtime.get(calendar.second))+"." +
string.format("%03d", nowtime.get(calendar.millisecond))+"]";
system.out.println(strdatetime);

//method 2
string msg="";
date date = new date();
simpledateformat sdf = new simpledateformat("yyyy/mm/dd hh:mm:ss.sss");
msg+="["+sdf.format(date)+"]";

system.out.println(msg);
}
}

运行结果:
[2013/08/09 05:54:32.578]
[2013/09/09 17:54:32.625]

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐