用整数值解析字符串 [英] Parse string with integer value to date

查看:88
本文介绍了用整数值解析字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这个值的字符串,例如:20130211154717我希望它像2013-02-11 15:47:17。我该怎么做?

I have a string with this value, for example: "20130211154717" I want it to be like "2013-02-11 15:47:17". How can I do that?

推荐答案

您可以使用两个 SimpleDateFormat :一个用于解析输入,另一个用于生成输出:

You can use two SimpleDateFormat: one to parse the input and one to produce the output:

String input =  "20130211154717";
Date d = new SimpleDateFormat("yyyyMMddhhmmss").parse(input);
String output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d);
System.out.println("output = " + output);

这篇关于用整数值解析字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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