zoukankan      html  css  js  c++  java
  • 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]




  • 相关阅读:
    _I、_O、_IO的含义
    ARM启动代码中_main 与用户主程序main()的区别
    ARM汇编程序中的伪指令
    oracle密码过期问题
    等待界面-调转页面前button篇
    等待效果
    winfrom中Application.Restart()
    自动刷新处理
    泛微E8二次开发
    我的菜园子
  • 原文地址:https://www.cnblogs.com/riskyer/p/3310803.html
Copyright © 2011-2022 走看看