Java輸出系統(tǒng)當前的日期(年月日時分秒毫秒)
更新時間:2013年09月10日 16:23:23 作者:
當前的日期輸出的方法有很多,本文為大家介紹下在java中是如何實現(xiàn)輸出年月日時分秒毫秒的,感興趣的朋友不妨參考下
復制代碼 代碼如下:
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]
您可能感興趣的文章:
- java用LocalDateTime類獲取當天時間、前一天時間及本周/本月的開始和結束時間
- 如何使用Java?8中DateTimeFormatter類型轉換日期格式詳解
- Java中@DateTimeFormat @JsonFormat失效原因及測試填坑
- Java關于后端怎么去接收Date、LocalDateTime類型的參數(shù)詳解
- Java8中對于LocalDateTime的序列化和反序列化問題
- Java8中的LocalDateTime你會使用了嗎
- java Date獲取年月日時分秒的實現(xiàn)方法
- java整數(shù)(秒數(shù))轉換為時分秒格式的示例
- Java里得到00:00:00格式的時分秒的Timestamp
- java datetime數(shù)據(jù)類型去掉時分秒的案例詳解
相關文章
jsp中使用frameset框架 邊框固定不讓更改邊框的大小
有時候可能要對自己布局好的頁面不讓用戶更改邊框的大小,這樣我們可以在frame里面添加noresize="noresize"屬性就可以實現(xiàn)其中的功能2014-07-07servlet+JSP+mysql實現(xiàn)文件上傳的方法
這篇文章主要介紹了servlet+JSP+mysql實現(xiàn)文件上傳的方法,涉及JSP文件傳輸與判斷及數(shù)據(jù)庫操作的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-11-11