java⽇期格式(年⽉⽇时分秒毫秒)lsbine;
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", (Calendar.YEAR))+"/"+
String.format("%02d", (Calendar.MONTH))+"/" +
String.format("%02d", (Calendar.DATE))+" " +
String.format("%02d", (Calendar.HOUR))+":" +
String.format("%02d", (Calendar.MINUTE))+":" +
String.format("%02d", (Calendar.SECOND))+"." +
String.format("%03d", (Calendar.MILLISECOND))+"]";
System.out.println(strDateTime);
//method 2
String msg="";
Date date = new Date();
java时间日期格式转换
SimpleDateFormat sdf = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss.SSS");
msg+="["+sdf.format(date)+"]";
System.out.println(msg);
}
}
运⾏结果:
[2018/04/25 02:51:33.379]
[2018/05/25 14:51:33.393]

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。