Java output the current date of the system

Copy codeThe code is as follows:

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))+”]”;

//method 2
String msg=””;
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(“YYYY/MM/dd HH:mm:ss.SSS”);


Results of operation:
[2013/08/09 05:54:32.578]
[2013/09/09 17:54:32.625]

Recommended Today

Share a simple blog

Series articles: Share a useful tp6 background management system Add Google login authentication in thinkphp6 background Share a simple blog JrkBlog_ Tp6.0 easy blog – you deserve it Project introduction Jrkblog blog is based on yfcmf background development Improve the following functions: Phpquerylist data collection,Phpword exports a word document,Practical and easy-to-use API interface,Upload OSS, cos […]