将long(其十进制表示形式表示yyyyMMdd .. date)转换为其他日期格式 [英] Converting long (whose decimal representation represents a yyyyMMdd.. date) to a different date format

查看:100
本文介绍了将long(其十进制表示形式表示yyyyMMdd .. date)转换为其他日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很长的表格

20120720162145
yyyymmddhhmmss

我必须将其转换为 2012-07-20 4:21 PM 表格。在Java中有没有办法使用 Date

I have to convert it to 2012-07-20 4:21 PM form. Is there any way in Java to do this using Date?

推荐答案

方法如下:

long input = 20120720162145L;

DateFormat inputDF = new SimpleDateFormat("yyyyMMddHHmmss");
DateFormat outputDF = new SimpleDateFormat("yyyy-MM-dd K:mm a");

Date date = inputDF.parse(""+input);

System.out.println(outputDF.format(date));

输出:

2012-07-20 4:21 PM

这篇关于将long(其十进制表示形式表示yyyyMMdd .. date)转换为其他日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆