【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来实现日期的转换. ...
随机推荐
- The bundle does not contain an app icon for iPhone / iPod Touch of exactly '120x120' pixels, in .pn
xcode 6.3 载发生时的应用'Missing recommended icon file - The bundle does not contain an app icon for iPhone ...
- ASP.NET Core 登录登出 - ASP.NET Core 基础教程 - 简单教程,简单编程
原文:ASP.NET Core 登录登出 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 登录登出 上一章节我们总算完善了注册的功能,而且也添加了一个用户,现 ...
- 使用 install.packages() 安装所需的包
1. 从 CRAN 上安装 install.packages("tm", dependencies = TRUE) tm 程序包用于文本挖掘(text mining) 2. 本地安 ...
- Android 动画具体解释Frame动画 (Drawable Animation)
Frame动画像gif画画,通过一些静态的图片,以实现动画效果. Android sdk该AnimationDrawable就是专门针对Frame动画,当然Frame动画也可在java代码或者xml中 ...
- jqmobi api 详细解说
0.$().get()得到是相应的元素. 如: $elem=$(".panal").get(0)); //得到了第一个panal类的元素 $elem_id = $elem.id ...
- XF 主从页面
using System; using Xamarin.Forms; using Xamarin.Forms.Xaml; [assembly: XamlCompilation (XamlCompila ...
- Win8 Metro(C#)数字图像处理--2.63图像指数增强
原文:Win8 Metro(C#)数字图像处理--2.63图像指数增强 [函数名称] 指数增强 WriteableBitmap IndexenhanceProcess(Writea ...
- ARTS 12.31 - 1.4
Algorithm 这是一道需要用动态规划的问题.求字符串的最长回文子序列. 复习了一遍动态规划,重点是要分析出最优解所包含的子问题的最优解,把过程描述为数学公式. 题目https://leetcod ...
- c#利用IronPython调用python的过程种种问题
c#利用IronPython调用python的过程种种问题 小菜鸟一枚,最新学习了Python,感觉语言各种简短,各种第三方类库爽歪歪,毕竟之前是从c#转来的,看到Python的request类各种爽 ...
- 设置代理调用WMTS服务
一.数据准备 1.链接:http://pan.baidu.com/s/1sjzCytR 密码:uugc,下载DotNet版本 2. 发布切片服务,打开ogc服务可产看到相应的符合ogc标准的服务,如下 ...