String.format()格式化日期(2)
在以前的开发中,日期格式化一直使用的是SimpleDateFormat进行格式化。今天发现String.format也可以格式化。当 然,两种方式的优劣没有进行深入分析。
1. 日期格式化 (2018/5/13 周日 中文环境下测试)
| 转换符 | 说明 | 结果 |
| %tb | 指定语言环境下的月份简称 | 五月 |
| %tB | 指定语言环境下的月份全称 | 五月 |
| %ta | 指定语言环境下周几的简称 | 星期日 |
| %tA | 指定语言环境下周几的全称 | 星期日 |
| %ty | 2位数的年份 | 18 |
| %tY | 4位数年份 | 2018 |
| %tm | 月份 | 05 |
| %te | 一个月中的某一天(1~31) | 13 |
| %td | 一个月中的某一天(01~31) | 13 |
| %tj | 一年中第几天 | 133 |
2. 时间格式化 (15:03:15.923 中文环境下测试)
| 转换符 | 说明 | 结果 |
| %tH | 小时(00~23) | 15 |
| %tI | 小时(01~12) | 03 |
| %tk | 小时(0~23) | 15 |
| %tl | 小时(1~12) | 3 |
| %tM | 分钟(00~59) | 35 |
| %tS | 秒(00~59) | 55 |
| %tL | 毫秒(000~999) | 923 |
| %tN | 9位数微妙(000000000~999999999) | 923000000 |
| %tp | 当前语言环境下上午/下午 | 下午 |
| %tz | 时区 | +0800 |
| %tZ | 时区 | CST |
| %ts | 从1970-01-01 00:00:00 到现在的秒 | 1526196955 |
| %tQ | 从1970-01-01 00:00:00 到现在的毫秒 | 1526196955923 |
3. 日期+时间 (2018/5/13 15:44:21 中文环境)
| 转换符 | 说明 | 结果 |
| %tF | 年-月-日 | 2018-05-13 |
| %tD | 月/日/年 | 05/13/18 |
| %tc | 全部时间日期 | 星期日 五月 13 15:44:21 CST 2018 |
| %tr | 时分秒 PM | 03:44:21 下午 |
| %tT | 时分秒 | 15:44:21 |
| %tR | 时分 | 15:44 |
T
String.format()格式化日期(2)的更多相关文章
- c#基础学习(0703)之string.Format格式化日期
C# string.Format格式化日期 DateTime dt = ,,,,,,); string.Format("{0:y yy yyy yyyy}",dt); //17 1 ...
- string.Format 格式化日期格式
DateTime dt = DateTime.Now;//2010年10月4日 17点05分 string str = ""; //st ...
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
- String.Format 格式化货币的小问题
今天在开发过程中,遇到一件让我觉得比较纳闷的事情:用String.Format 格式化充值金额的时候,我这样处理: String.Format("{0:C2}", dr[" ...
- 使用printf和String.format格式化输出
格式化输出 在哪些情况下使用格式化输出: 异常打印到日志中使用格式化输出有利于排查错误原因: printf格式化 示例: public class PrintfTest { public static ...
- string.Format 格式化输出日期
string.Format("{0:d}",System.DateTime.Now) 结果为:2009-3-20 (月份位置不是03) string.Format("{0 ...
- String.Format,DateTime日期时间格式化
DateTime dt = DateTime.Now;//2010年10月4日 17点05分 string str = ""; //st ...
- string.Format格式化用法详解
1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...
- string.Format 格式化时间,货币
1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...
随机推荐
- Angular单元测试系列
Angular单元测试系列 - 大纲Angular单元测试系列 - 简介Angular单元测试系列 - 如何使用Jasmine进行Angular单元测试Angular单元测试系列 - Router.C ...
- unity屏幕坐标转世界坐标结果为(0,0,0)
代码: wv转出来一直为(0,0,0),卡了好久,问别人说要转化的屏幕坐标Z不能为0 阿西吧!特此记录
- node-glob 匹配通配符
1.https://www.cnblogs.com/liulangmao/p/4552339.html 2.https://github.com/isaacs/node-glob 3.https:// ...
- date.timezone not set in php.ini. Please contact ...解决方案
无论是在LAMP还是在LNMP系统环境下, 只要PHP的版本在5.3及其以上的版本时, 无论是在安装oscommerce, 还是在安装zen cart, 以及其他的CMS时, 都会遇到如下所示的错误信 ...
- Java 进阶7 并发优化 1 并行程序的设计模式
本章重点介绍的是基于 Java并行程序开发以及优化的方法,对于多核的 CPU,传统的串行程序已经很好的发回了 CPU性能,此时如果想进一步提高程序的性能,就应该使用多线程并行的方式挖掘 CPU的 ...
- Windows 下 左Ctrl和Caps交换
将以下文本存为后缀为.reg文件,运行并重启即可 左Ctrl和Caps交换 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTE ...
- C# 设计模式巩固 - 简单工厂模式
前言 设计模式的文章很多.鄙人不才文笔也不咋地.写这篇只为巩固下基础知识,万一不小心帮到了您,是我莫大的荣幸!写的不好欢迎码友指正,废话结束开始进入正题. 介绍 - 简单工厂模式 官方定义:(尴尬~貌 ...
- LeetCode OJ:Number of Islands(孤岛计数)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- 一台服务器的IIS绑定多个域名
等待十分钟: 在IIS上配置:
- 剑指offer--46.字符流中第一个不重复的字符
双端队列 -------------------------------------------------------- 时间限制:1秒 空间限制:32768K 热度指数:113070 本题知识点: ...