java时间格式年月日时分秒_java日期格式(年月日时分秒毫秒)

java日期格式(年月日时分秒毫秒)

2020-08-13 07:09

阅读数 79

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); } }

运行结果:

[2018/04/25 02:51:33.379]

[2018/05/25 14:51:33.393]

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页