Java_格式化日期和时间
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_格式化日期和时间相关推荐
- ExifTool如何格式化日期和时间信息以进行书写
xifTool是一个独立于平台的Perl库,另外还有一个命令行应用程序,用于读取,编写和编辑各种文件中的元信息.这里为大家介绍的就是使用ExifTool进行格式化日期和时间信息以进行书写,感兴趣的朋友 ...
- mysql格式化日期和时间
date_format(datetime,formatting)可以格式日期和时间(例如 YYYY-MM-DD HH:MM:SS)和(HH:MM:SS) time_format(datetime,fo ...
- 如何格式化日期和时间
JAVA时间格式化处理 日期格式化 import java.util.Date; import java.text.SimpleDateFormat; class dayTime { public s ...
- Linux脚本获取日期,Shell脚本获取格式化日期与时间
#!/bin/sh # upload logs to hdfs source /etc/profile #获取昨天日期 yyyyMMdd 格式 yesterday=`date --date='1 da ...
- JAVA格式化日期、时间,及获取每月第几周 每周第几天 每月第几天
Date dt = new Date(); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");//格式化 System ...
- Java格式化日期和时间模式占位符
- python linux 时间格式化,Python3 格式化日期
导读 Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 我们可以使用 time 模块的 strftime 方法来格式化日期,: time.strftime(fo ...
- python输出时间格式_python中日期和时间格式化输出的方法小结_python
这篇文章主要介绍了python中日期和时间格式化输出的方法,实例总结了Python常见的日期与事件操作技巧,非常具有实用价值,需要的朋友可以参考下 本文实例总结了python中日期和时间格式化输出的方 ...
- python中日期和时间格式化输出的方法
1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" #将其转换为时间数组 import time timeArray = time.strp ...
最新文章
- audio type多种类型_http content-type常见文件格式类型
- 如何将命令行参数传递给Node.js程序?
- grafana3.1.0安装配置
- 分享Kali Linux 2017年第二周镜像文件
- jxl生成表格(合并单元格,字体,样式)
- vuepress build提示YAMLException: end of the stream or a document separator is expected at line 7, colu
- Arduino Uno + Lora shield rf95_server 提示错误“Init failed!”
- javascript演变史_检查有史以来最著名JavaScript错误之一
- Bootstrap3基础 glyphicon 设置图标的颜色与大小
- Python第十课(函数3)
- LC-1186 连续子数组中可删除一个数的最大和
- 如何将视频转换为HEVC / H.265和AVC / H.264
- 计算机平均工资公式数值型,平均工资的计算方式
- 深度篇——实例分割(三) 细说 mask rcnn 实例分割代码 训练自己数据 之 相关网络,数据处理,工具等
- C#简单使用ManagedWifi
- js和ts两种 将 小写金额转中文大写汉字,阿拉伯数字金额格式化成中文大写汉字,数字金额转换成财务发票大写中文
- java的OpenGL学习资料
- 在Winform中上传文件的工具类-ResourceMgr
- C语言 输入一个整数n,求出其阶乘
- 【bypass】403绕过