convert string to date and time as am/pm format(将字符串转换为上午/下午格式的日期和时间)
问题描述
使用 SimpleDateFormat 格式化就够了?或者否则我会转向任何新的 API?
using SimpleDateFormat is enough to format? or otherwise i will shift to any new API?
我的预期结果是(印度区):
My expected result is (India zone):
推荐答案
记住 Date
对象没有固有格式,你需要两个 DateFormat
对象来产生你想要的结果seek - 一个解析,另一个格式化:
Remembering that Date
objects have no inherent format, you need two DateFormat
objects to produce the result you seek - one to parse and another to format:
输出:
注意格式中引用的序列的使用,例如 "'Date : '"
,它在格式模式中被视为文字.
Note the use of quoted sequences in the format, such a "'Date : '"
, which is treated as a literal within the format pattern.
这篇关于将字符串转换为上午/下午格式的日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!