Java日期处理:解析给定格式日期为标准格式期

/**
 * @param String  emsTime:需要转换的日期
 * @param SimpleDateFormat sdf_2:标准转换格式
 * @param String emsTimeFormat_1:最2转换方式
 * @throws
 * @author imanong
 * ModifyDate:2012-05-09   
 */

public class ToTime {

        public static void main(String[] args) {
            String emsTime = "20110624084955.0";
            String emsTimeFormat_1 = emsTime.substring(0,4)+"-"+emsTime.substring(4,6)+"-"+emsTime.substring(6, 8)
              +" "+emsTime.substring(8, 10)+":"+emsTime.substring(10, 12)+":"+emsTime.substring(12, 14);
            
            SimpleDateFormat sdf_1 = new SimpleDateFormat("yyyyMMddHHmmss.0");
            SimpleDateFormat sdf_2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String emsTimeFormat_2 = "";
            try {
                emsTimeFormat_2 = sdf_2.format(sdf_1.parse(emsTime));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            System.out.println(emsTimeFormat_2);   //打印标准格式解析的日期
            System.out.println(emsTimeFormat_1);  //打印最2格式解析的日期
        }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值