java UTC时间格式化
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone; /**
* @author 王睿
* @date 2019-01-24 14:32
*/
public class TimeFormat { public static void main(String[] args) throws ParseException {
String text = "2019-01-03T08:26:15.503162206Z";
text = "2019-01-03T08:26:15Z";
Date date = parseUTCText(text);
System.out.println(date);
} /**
* @param text 时间字符串,格式支持两种
* 1、不包含毫秒值,如"2019-01-03T08:26:15Z";
* 2、支持任意位数的毫秒值:2019-01-03T08:26:15.503162206Z;
* 转换出来的Date类型精度知道毫秒位
* @return
* @throws ParseException
*/
public static Date parseUTCText(String text) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
if (text.indexOf(".") > -1) {
String prefix = text.substring(0, text.indexOf("."));
String suffix = text.substring(text.indexOf("."));
if (suffix.length() >= 5) {
suffix = suffix.substring(0, 4) + "Z";
} else {
int len = 5 - suffix.length();
String temp = "";
temp += suffix.substring(0, suffix.length() - 1);
for (int i = 0; i < len; i++) {
temp += "0";
}
suffix = temp + "Z";
}
text = prefix + suffix;
} else {
text = text.substring(0, text.length() - 1) + ".000Z";
}
Date date = sdf.parse(text);
return date;
} }
java UTC时间格式化的更多相关文章
- java UTC时间和local时间相互转换
java UTC时间和local时间相互转换 1.local时间转UTC时间 /** * local时间转换成UTC时间 * @param localTime * @return */ public ...
- Java 日期时间格式化
在此记录Java日期时间格式化转换符,方便以后有需要时查找. 1.日期格式化 2.时间格式化 3.格式化常见的日期时间组合
- Java UTC时间与本地时间互相转换
协调世界时,又称世界统一时间.世界标准时间.国际协调时间.由于英文(CUT)和法文(TUC)的缩写不同,作为妥协,简称UTC. 这套时间系统被应用于许多互联网和万维网的标准中,例如,网络时间协议就是协 ...
- Java 学习 时间格式化(SimpleDateFormat)与历法类(Calendar)用法详解
基于Android一些时间创建的基本概念 获取当前时间 方式一: Date date = new Date(); Log.e(TAG, "当前时间="+date); 结果: E/T ...
- java 秒时间格式化
public static String durationFormat(Integer totalSeconds) { if (totalSeconds == null || totalSeconds ...
- 随手一记,关于Java日期时间格式化
在Java中,我们大多数情况下格式化日期都是使用simpleDateFormat,比如把一个日期格式化成:2019-12-31的形式,我们一般定义模板为:yyyy-MM-dd的形式. 我们需要注意的是 ...
- java给时间格式化
package com.apress.springrecipes.sequence; import java.text.DateFormat;import java.text.SimpleDateFo ...
- 将utc时间格式化的代码
/** * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).12小时(h).24小时(H).分(m).秒(s).周(E).季度(q) 可以用 1-2 个占位符 * ...
- Java日期时间API系列19-----Jdk8中java.time包中的新的日期时间API类,ZonedDateTime与ZoneId和LocalDateTime的关系,ZonedDateTime格式化和时区转换等。
通过Java日期时间API系列6-----Jdk8中java.time包中的新的日期时间API类中时间范围示意图:可以很清晰的看出ZonedDateTime相当于LocalDateTime+ZoneI ...
随机推荐
- C# 以函数Action/Func/Task作为方法参数
以Action.Func.Task作为方法参数,mark一下 以Action为参数 public void TestAction() { //Action参数 ExecuteFunction(() = ...
- AJAX获取JSON WEB窗体代码
1.添加引用 using System.Web.Services; 2.添加方法 [WebMethod] public static string getFoodClasses(int parentI ...
- 初学Shiro
Shiro Shiro是什么? Apache Shiro是Java的一个安全(权限)框架. Shiro可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE环境下,也可以用者JavaEE环境下 ...
- POJ1006: 中国剩余定理的完美演绎
POJ1006: 中国剩余定理的完美演绎 问题描述 人自出生起就有体力,情感和智力三个生理周期,分别为23,28和33天.一个周期内有一天为峰值,在这一天,人在对应的方面(体力,情感或智力)表现最 ...
- C# 通用单例窗体类
/// <summary> /// 通用的单例制作器 /// </summary> /// <typeparam name="T"></t ...
- Easyui 关闭jquery-easui tab标签页前触发事件
关闭jquery-easui tab标签页前触发事件 by:授客 QQ:1033553122 测试环境 jquery-easyui-1.5.3 需求场景 点击父页面tab 页关闭按钮时,需要做判断,判 ...
- bcrypt 安装不成功解决办法
同一个项目,公司和家里的 node.js 的版本不同,导致项目安装依赖包时 bcrypt 安装不成功. 家里的版本为:8.11.3 公司的版本为:10.14.2 在当前项目中执行完下面两个命令后,报错 ...
- git错误--ssh: Could not resolve hostname ssh.github.com: Name or service not known--解决方式
错误如下: git push origin ssh: Could not resolve hostname ssh.github.com: Name or service not known fata ...
- django logging
LOG_LEVEL = 'DEBUG' LOGGING = { 'version' : 1, 'disable_existing_loggers' : True, 'formatters' : { ' ...
- 【原】使用IDEA创建Maven工程时提示"...xxx/pom.xml already exists in VFS"的解决
问题:使用IDEA创建Maven工程时提示"...xxx/pom.xml already exists in VFS",怎么办? 解决:如果只是删除工程,还会有这样的提示.说到底, ...