1.常用日期和时间的格式化转换符

import java.util.Date;public class DateFormatTest {public static void main(String[] args) {Date today = new Date();System.out.println(String.format("%tF",today));//2021-11-25System.out.println(String.format("%tD",today));//11/25/21System.out.println(String.format("%tr",today));//07:55:18 下午System.out.println(String.format("%tT",today));//19:55:18System.out.println(String.format("%tR",today));//19:55}}

2.日期的格式化转换符

import java.util.Date;
import java.util.Locale;public class DateFormatTest02 {public static void main(String[] args) {Date date = new Date(1266681600000L);System.out.println(date);//Sun Feb 21 00:00:00 CST 2010System.out.println(String.format(Locale.US,"%tb",date));//Feb b或h都行 获取月份简称System.out.println(String.format(Locale.US, "%tB",date));//February  获取月份全称System.out.println(String.format("%ta", date));//周日  获取星期简称System.out.println(String.format("%tA", date));//星期日  获取星期全称System.out.println(String.format("%tY", date));//2010  获取年(不足四位前面补0)System.out.println(String.format("%ty", date));//10  获取年的后两位(不足2位前面补0)System.out.println(String.format("%tm", date));//02  获取年的前两位(不足2位前面补0)System.out.println(String.format("%td", date));//21  获取日(不足2位前面补0)System.out.println(String.format("%te", date));//21  获取日System.out.println(String.format("%tj", date));//052  获取一年的第多少天}}

3.时间的格式化转换符

import java.util.Date;
import java.util.Locale;public class DateFormateTest03 {public static void main(String[] args) {Date now = new Date();System.out.println("当前时间:"+now);System.out.println(String.format("%tH", now));//获取24小时制的小时(不足2位前面补0)System.out.println(String.format("%tk", now));//获取24小时制的小时(不足2位前面不补0)System.out.println(String.format("%tI", now));//获取12小时制的小时(不足2位前面补0)System.out.println(String.format("%tl", now));//获取12小时制的小时(不足2位前面不补0)System.out.println(String.format("%tM", now));//获取分钟(不足2位前面补0)System.out.println(String.format("%tS", now));//获取获取秒(不足2位前面补0)System.out.println(String.format("%tL", now));//获取3位的毫秒(不足3位前面补0)System.out.println(String.format("%tN", now));//获取9位的毫秒(不足9位前面补0)System.out.println(String.format("%tp", now));//显示上、下午标记System.out.println(String.format(Locale.US,"%tp", now));}}

Java_格式化日期和时间相关推荐

  1. ExifTool如何格式化日期和时间信息以进行书写

    xifTool是一个独立于平台的Perl库,另外还有一个命令行应用程序,用于读取,编写和编辑各种文件中的元信息.这里为大家介绍的就是使用ExifTool进行格式化日期和时间信息以进行书写,感兴趣的朋友 ...

  2. mysql格式化日期和时间

    date_format(datetime,formatting)可以格式日期和时间(例如 YYYY-MM-DD HH:MM:SS)和(HH:MM:SS) time_format(datetime,fo ...

  3. 如何格式化日期和时间

    JAVA时间格式化处理 日期格式化 import java.util.Date; import java.text.SimpleDateFormat; class dayTime { public s ...

  4. Linux脚本获取日期,Shell脚本获取格式化日期与时间

    #!/bin/sh # upload logs to hdfs source /etc/profile #获取昨天日期 yyyyMMdd 格式 yesterday=`date --date='1 da ...

  5. JAVA格式化日期、时间,及获取每月第几周 每周第几天 每月第几天

    Date dt = new Date(); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");//格式化 System ...

  6. Java格式化日期和时间模式占位符

  7. python linux 时间格式化,Python3 格式化日期

    导读 Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 我们可以使用 time 模块的 strftime 方法来格式化日期,: time.strftime(fo ...

  8. python输出时间格式_python中日期和时间格式化输出的方法小结_python

    这篇文章主要介绍了python中日期和时间格式化输出的方法,实例总结了Python常见的日期与事件操作技巧,非常具有实用价值,需要的朋友可以参考下 本文实例总结了python中日期和时间格式化输出的方 ...

  9. python中日期和时间格式化输出的方法

    1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" #将其转换为时间数组 import time timeArray = time.strp ...

最新文章

  1. audio type多种类型_http content-type常见文件格式类型
  2. 如何将命令行参数传递给Node.js程序?
  3. grafana3.1.0安装配置
  4. 分享Kali Linux 2017年第二周镜像文件
  5. jxl生成表格(合并单元格,字体,样式)
  6. vuepress build提示YAMLException: end of the stream or a document separator is expected at line 7, colu
  7. Arduino Uno + Lora shield rf95_server 提示错误“Init failed!”
  8. javascript演变史_检查有史以来最著名JavaScript错误之一
  9. Bootstrap3基础 glyphicon 设置图标的颜色与大小
  10. Python第十课(函数3)
  11. LC-1186 连续子数组中可删除一个数的最大和
  12. 如何将视频转换为HEVC / H.265和AVC / H.264
  13. 计算机平均工资公式数值型,平均工资的计算方式
  14. 深度篇——实例分割(三) 细说 mask rcnn 实例分割代码 训练自己数据 之 相关网络,数据处理,工具等
  15. C#简单使用ManagedWifi
  16. js和ts两种 将 小写金额转中文大写汉字,阿拉伯数字金额格式化成中文大写汉字,数字金额转换成财务发票大写中文
  17. java的OpenGL学习资料
  18. 在Winform中上传文件的工具类-ResourceMgr
  19. C语言 输入一个整数n,求出其阶乘
  20. 【bypass】403绕过

热门文章

  1. 数据库高并发的处理方法
  2. Word 中公式居中,编号靠右
  3. Vue全局变量和方法的使用
  4. js判断是手机访问还是电脑访问
  5. 使用JS调用手机本地摄像头或者相册图片识别二维码/条形码
  6. MAC协议之CRC校验码
  7. HK32F103CBT6A最小开发版系统
  8. 198个经典C#WinForm实例源码
  9. IT 圈里有哪些经常被读错的词? (转载)
  10. noip2005篝火晚会 2008.10.18