从日期字符串中提取时间 [英] Extract time from date String
本文介绍了从日期字符串中提取时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何格式化2010-07-14 09:00:02
日期字符串仅描述9:00
?
How can I format the "2010-07-14 09:00:02"
date string to depict just "9:00"
?
推荐答案
使用 SimpleDateFormat
在日期字符串和真实 日期
对象。使用 Date
作为起点,您可以根据 SimpleDateFormat
的javadoc中定义的各种模式轻松应用格式化(点击Javadoc的蓝色代码链接)。
Use SimpleDateFormat
to convert between a date string and a real Date
object. with a Date
as starting point, you can easily apply formatting based on various patterns as definied in the javadoc of the SimpleDateFormat
(click the blue code link for the Javadoc).
这是一个开球示例:
String originalString = "2010-07-14 09:00:02";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(originalString);
String newString = new SimpleDateFormat("H:mm").format(date); // 9:00
这篇关于从日期字符串中提取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文