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]

转载请注明:代码学堂>编程开发 > jsp教程 > Java输出系统当前的日期(年月日时分秒毫秒)

1. 本站所有资源来源于用户上传和网络,因此不包含技术服务请大家谅解!如有侵权请邮件联系客服!10210454@qq.com
2. 本站不保证所提供所有下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理,有奖励!
3. 您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源!如用于商业或者非法用途,与本站无关,一切后果请用户自负!
4. 如果您也有好的资源或教程,您可以投稿发布,成功分享后有RB奖励和额外RMB收入!

磊宇堂正在使用的服务器 维护管理由磊宇云服务器提供支持

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

提供最优质的资源集合

立即查看 了解详情