【dateFormatSymbols】JAVA特殊日期格式转换
记录:特殊日期格式转换,如将yyyyMMdd转为01MAY2019
public static final String DATE_VIP_FORMAT = "yyyyMMdd";
public static String format(Date targetDate, String formatStr){
if (targetDate == null || StringUtils.isBlank(formatStr)){
return null;
}
SimpleDateFormat format = new SimpleDateFormat(formatStr);
return format.format(targetDate);
}
public static Date parse(String date, String pattern){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
try {
return simpleDateFormat.parse(date);
} catch (ParseException e) {
//blocker解决
logger.error("parse date error for input String {}",date);
}
return null;
}
public static String formatVipDateStr(Date date) {
return format(date, DATE_VIP_FORMAT);
}
public static Date parseVipDateStr(String date) {
return parse(date, DATE_VIP_FORMAT);
}
/**
* 将01MAY2019 转换为yyyyMMdd
*/
public static String getVipStr(String date){
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMMyyyy", Locale.ENGLISH);
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
dateFormatSymbols.setShortMonths(new String[]{"JAN", "FEB", "MAR"
, "APR", "MAY", "JUN"
, "JUL", "AUG", "SEP"
, "OCT", "NOV", "DEC"});
dateFormat.setDateFormatSymbols(dateFormatSymbols);
Date parse = dateFormat.parse(date);
return formatVipDateStr(parse);
} catch (ParseException e) {
logger.error("parse VIP date error for input String {}",date);
}
return null;
}
/**
* 将yyyyMMdd转为01MAY2019
*/
public static String getVipFmt(String dateStr){
try {
//获取date对象
Date date = parseVipDateStr(dateStr);
SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMMyyyy", Locale.ENGLISH);
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
dateFormatSymbols.setShortMonths(new String[]{"JAN", "FEB", "MAR"
, "APR", "MAY", "JUN"
, "JUL", "AUG", "SEP"
, "OCT", "NOV", "DEC"});
dateFormat.setDateFormatSymbols(dateFormatSymbols);
String format = dateFormat.format(date);
return format;
} catch (Exception e) {
logger.error("parse VIP date error for input String {}",dateStr);
}
return null;
}
public static void main(String[] args) {
String vipStr = getVipFmt("20190503");
System.out.println(vipStr);
}
【dateFormatSymbols】JAVA特殊日期格式转换的更多相关文章
- Java时间日期格式转换 转自:http://www.cnblogs.com/edwardlauxh/archive/2010/03/21/1918615.html
Java时间格式转换大全 import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @ ...
- Java时间日期格式转换
1.这个是系统自动默认的时间格式,或者说是美式格式: Long time = System.currentTimeMillis(); Date date = new Da ...
- java常见日期格式转换以及日期的获取
package com.test.TestBoot.SingleModel;import java.text.SimpleDateFormat;import java.util.Date;public ...
- Java时间日期格式转换Date转String和String转Date
Java时间格式转换大全 import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @ ...
- JAVA中日期格式转换各个字母代表含义
G Era 标志符 Text AD y 年 Year 1996; 96 M 年中的月份 Month July; Jul; 07 w 年中的周数 Number 27 W ...
- java 获取当前日期和特殊日期格式转换
1.获取当前日期: package com.infomorrow.dao; import java.sql.Timestamp; import java.util.Calendar; import ...
- java中日期格式的转换和应用
java中主要有3个类用于日期格式转换 DateFormat .SimpleDateFormat.Calendar SimpleDateFormat函数的继承关系: java.lang.Obje ...
- Java练习 SDUT-2246_时间日期格式转换
时间日期格式转换 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 对于日期的常用格式,在中国常采用格式的是"年 ...
- JAVA对象转换为JSON及日期格式转换处理
1.JSON日期格式转换 默认JSON对DATE类型会转换成一个多属性对象, 而不是单独的一个字符串, 在某些应用处理上不是很方便, 可以利用JsonValueProcessor来实现日期的转换. ...
随机推荐
- [OpenGL]OpenGL坐标系和坐标变换
OpenGL通过摄像机的模拟.要实现一个三维计算机图形重大转变,这是几何变换(模型转换-查看转型(两者统称为几何变换)).投影.作物转型.口变换等.同一时候,OpenGL还实现了矩阵堆栈等.理解掌握了 ...
- STL优先级队列
priority_queue 这是一个优先级队列的所有权值概念单向队列queue.在这个队列中.全部元素是按优先级排列的(也能够觉得queue是个按进入队列的先后做为优先级的优先级队列--先进入队列的 ...
- 微信小程序之加载更多(分页加载)实例
业务需求: 列表滚动到底部时,继续往上拉,加载更多内容 必备参数: (1)pageindex: 1 //第几次加载 (2)callbackcount: 15 //需要返回数据的个数 其他参数: 根据接 ...
- .net reactor 学习系列(一)---.net reactor介绍
原文:.net reactor 学习系列(一)---.net reactor介绍 学习.net已经一年多了,从语言的编写到框架类库的运用再到.net三大解决方案的了解(WF,WCF,WPF ...
- Emgu-WPF 激光雷达研究-移动物体跟踪2
原文:Emgu-WPF 激光雷达研究-移动物体跟踪2 初步实现了去燥跟踪,并用圆点标注障碍物 https://blog.csdn.net/u013224722/article/details/8078 ...
- WPF编游戏系列 之二 图标效果
原文:WPF编游戏系列 之二 图标效果 本篇将要实现图标的两个效果:1. 显示图标标签,2. 图标模糊效果.在上一篇中提到Image没有HTML <img>的Title属性( ...
- OnPropertyChanged的使用
#region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; ...
- VS2012发布到XP平台
默认情况下,你的VS2012工程发布后,在XP下运行会出现提示“not a valid win32 application”. 微软推出了Visual Studio 2012 update 1可以支持 ...
- 为什么腾讯总能做出好产品?(在互联网行业,往往仅凭一个关键产品就足以改变整个公司的格局)MSN失败在不以用户体验为中心
投递人 itwriter 发布于 2017-07-10 11:16 评论(36) 有3401人阅读 原文链接 [收藏] « » 本文来自微信公众号“郑志昊 Peter”,作者李翔.郑志昊:博客园经授权 ...
- Cordova页面加载外网图片失败,Refused to load the image
原文:Cordova页面加载外网图片失败,Refused to load the image 1.使用Cordova页面加载外网图片失败,抛出异常 Refused to load the image ...