记录:特殊日期格式转换,如将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特殊日期格式转换的更多相关文章

  1. Java时间日期格式转换 转自:http://www.cnblogs.com/edwardlauxh/archive/2010/03/21/1918615.html

    Java时间格式转换大全 import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @ ...

  2. Java时间日期格式转换

    1.这个是系统自动默认的时间格式,或者说是美式格式: Long time = System.currentTimeMillis();                Date date = new Da ...

  3. java常见日期格式转换以及日期的获取

    package com.test.TestBoot.SingleModel;import java.text.SimpleDateFormat;import java.util.Date;public ...

  4. Java时间日期格式转换Date转String和String转Date

    Java时间格式转换大全 import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @ ...

  5. JAVA中日期格式转换各个字母代表含义

    G  Era 标志符  Text  AD  y  年  Year  1996; 96  M  年中的月份  Month  July; Jul; 07  w  年中的周数  Number  27  W  ...

  6. java 获取当前日期和特殊日期格式转换

     1.获取当前日期: package com.infomorrow.dao; import java.sql.Timestamp; import java.util.Calendar; import ...

  7. java中日期格式的转换和应用

    java中主要有3个类用于日期格式转换    DateFormat .SimpleDateFormat.Calendar SimpleDateFormat函数的继承关系: java.lang.Obje ...

  8. Java练习 SDUT-2246_时间日期格式转换

    时间日期格式转换 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 对于日期的常用格式,在中国常采用格式的是"年 ...

  9. JAVA对象转换为JSON及日期格式转换处理

    1.JSON日期格式转换 默认JSON对DATE类型会转换成一个多属性对象, 而不是单独的一个字符串, 在某些应用处理上不是很方便,  可以利用JsonValueProcessor来实现日期的转换. ...

随机推荐

  1. C#中的String.Format介绍

    关键字:C# string.format作者:txw1958原文:http://www.cnblogs.com/txw1958/archive/2012/11/15/csharp-string_for ...

  2. Beginner’s Tutorial: 3D Line and Border Effects in XAML

    This mini-tutorial might be for you if you’re having troubles finding the right line colors to achie ...

  3. c#引用相等性比较(ReferenceEquals)

    Object.ReferenceEquals方法原型 public static bool ReferenceEquals( object objA, object objB) namespace T ...

  4. Android学习路径(22)应用Fragment建立动态UI——构建一个灵活UI

    当你设计你的应用来支持多个屏幕尺寸.你能够基于可用的屏幕空间通过在不同的布局上重用fragment来优化用户体验. 比如,在一个手机上.使用单面板(一次仅仅显示一个fragment)的用户体验更加合适 ...

  5. WCF的几个注意事项

    wcf托管服务注意的问题 加上项目分为客户端-WCF服务-逻辑层-数据库三层wcf一直出现异常,说没有初始化啊之类的,如果你的逻辑代码确定没有问题的话,思考是不是wcf的配置文件(app.config ...

  6. WPF DataGrid支持的列类型

    WPF DataGrid支持下面几种列类型: DataGridTextColumn DataGridCheckBoxColumn DataGridComboBoxColumn DataGridHype ...

  7. sql server 定时备份数据库

    CREATE PROCEDURE [dbo].[SP_DBBackup_EveryNight_Local] @cycle INT, ---保存周期 @IsLocal INT, ---是否为本地 0表示 ...

  8. SqlServer 可更新订阅升级字段队列数据丢失原因

    原文:SqlServer 可更新订阅升级字段队列数据丢失原因 之前简单描述过数据冲突发生的原因:SQLServer可更新订阅数据冲突的一个原因 ,但具体内部原理是怎么丢失的还不清楚,今天补充说明.可更 ...

  9. SQLServer 订阅过期解决方法

    原文:SQLServer 订阅过期解决方法 由于分发数据库执行一个较长的事务,达到了系统预定的72小时,导致了该订阅过期,数据库分发代理已不可再启用,提示错误如下: 错误信息:已将此(这些)订阅标记为 ...

  10. Excel的Range对象(C#)

    原文:Excel的Range对象(C#) Range 对象是 Excel 应用程序中最经常使用的对象:在操作 Excel 内的任何区域之前,都需要将其表示为一个 Range 对象,然后使用该 Rang ...