FastDateFormat 时间戳转换
来源:互联网 发布:算法推荐类app 编辑:程序博客网 时间:2024/04/29 07:15
SimpleDateFormat来做Date到String的类型转换,建议使用Apache commons-lang中的FastDateFormat。
因为JDK里自带的SimpleDateFormat存在线程不安全问题。
直接贴上代码,参数里是long型的时间戳
/** * Created by huanghong on 2016/11/4. */@Servicepublic class DateFormatService { public static final TimeZone UTC = TimeZone.getTimeZone("UTC"); public static final FastDateFormat ISO_DATETIME_TIME_ZONE_FORMAT_WITH_MILLIS = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", UTC); public String dateFormat(long timestamp) { return ISO_DATETIME_TIME_ZONE_FORMAT_WITH_MILLIS.format(timestamp); }}
UTC是国际时区。
通过FastDateFormat直接转化
导入三个包
import org.apache.commons.lang.time.FastDateFormat;import org.springframework.stereotype.Service;import java.util.TimeZone;
简单的小工具类。
0 0
- FastDateFormat 时间戳转换
- 使用FastDateFormat
- 时间戳转换时间
- 时间戳转换时间
- linux 时间戳/时间转换
- MySQL时间戳转换时间
- 时间格式时间戳转换
- 时间转换位时间戳
- 时间戳转换成时间
- 时间戳转换成时间
- 时间戳与时间转换
- 时间戳转换时间格式
- 时间戳转换成时间
- 时间戳转换为时间
- python-时间戳转换时间
- js 时间戳转换时间
- linux 时间戳转换/dmesg 时间转换
- linux 时间戳转换/dmesg 时间转换
- 菜鸟之路——Spring MVC(五)ViewResolver
- android开发(二)-- application功能(讲的不错)
- 每日算法_编程之美_重建二叉树
- 解决eclipse导出war包时漏掉自定义的用户库中的jar包
- 页面请求后台,导出Excel
- FastDateFormat 时间戳转换
- CArray的用法
- win7音量系统图标无法打开
- 如何进入百度、阿里,一个6年Android老司机的面经
- C数据类型的长度
- Js_闭包
- [小贱] 小贱学C#笔记之Newtonsoft.Json(一)
- PHP获取用户访问IP地址的5种方法
- 使用JDBC 访问数据库