SimpleDateFormat的pattern
来源:互联网 发布:找程序员男朋友的坏处 编辑:程序博客网 时间:2024/06/03 07:32
参考官方文档:
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
SimpleDateFormat类允许的字符
static final String patternChars = “GyMdkHmsSEDFwWahKzZYuXL”;
字符解释:
示例一:
dateStr: 2017-10-19 11:16:00.083+08:00
pattern: yyyy-MM-dd HH:mm:ss.SSSX
解释:
S=毫秒 .SSS代表秒后面的小数为83毫秒
X代表时区+08:00 即北京时间的11.16分
附上线程安全的SimpleDateFormat类
/** * 线程安全的dataformat 避免了单线程内重复创建的开销 */public class ThreadLocalDateFormat { private static final String ULOG_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss.SSSX"; private static ThreadLocal<DateFormat> threadLocalDateFormat = new ThreadLocal<>(); public static DateFormat getUlogDateFormat() { DateFormat dateFormat = threadLocalDateFormat.get(); if (dateFormat == null) { dateFormat = new SimpleDateFormat(ULOG_DATE_PATTERN); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+8")); threadLocalDateFormat.set(dateFormat); } return dateFormat; } public static long getUlogTimestamp(String ulogDateStr) throws ParseException { return getUlogDateFormat().parse(ulogDateStr).getTime(); }}
阅读全文
0 0
- SimpleDateFormat的pattern
- SimpleDateFormat的pattern模式YYYYMMDDHHmmSS
- SimpleDateFormat的pattern模式YYYYMMDDHHmmSS
- SimpleDateFormat 中的 pattern 字母
- SimpleDateFormat的用法
- SimpleDateFormat的常用方法
- SimpleDateFormat 的使用
- SimpleDateFormat的用法
- SimpleDateFormat的用法
- SimpleDateFormat的问题
- SimpleDateFormat 的使用方法
- 万恶的SimpleDateFormat
- 关于SimpleDateFormat的应用
- simpledateformat 的使用方法
- SimpleDateFormat的使用详解
- SimpleDateFormat的方法使用
- SimpleDateFormat 的简单使用
- SimpleDateFormat的线程安全问题
- 奥威Power-BI For金蝶用友标准BI解决方案 -人力资源-人员招聘分析
- C语言实现简单的面向对象例子
- 【学习】如何用jQuery获取iframe中的元素
- JAVA 编程思想第11章--持有对象
- 远程访问jupyter notebook
- SimpleDateFormat的pattern
- ajax获取json数据然后将其装载到jqgrid实现
- HTTP协议介绍
- CSS字体大小变化问题
- OpenGL
- 枚举
- sudo: no tty present and no askpass program specified 解决方法
- 用tomcat部署图片服务器
- Linux shell脚本基础学习详细介绍(完整版)2