广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >Java输出系统当前的日期(年月日时分秒毫秒)
  • 630
分享到

Java输出系统当前的日期(年月日时分秒毫秒)

当前日期年月日时分秒 2022-11-15 22:11:20 630人浏览 薄情痞子
摘要

package test.remote.tools.combine; import java.text.SimpleDateFORMat; import java.util.Cal


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]

--结束END--

本文标题: Java输出系统当前的日期(年月日时分秒毫秒)

本文链接: https://www.lsjlt.com/news/172460.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作