日期时间格式字符串模式
有人可以指导我使用正确的格式字符串以以下格式显示时间吗?
Original: #7/28/2011 09:00:03 AM#
Required Format: 9am
//BUT if the minutes part contains a value I want it to look like this
Original: #7/28/2011 09:21:03 AM#
Required Format: 9:21am
我可以使用一种格式字符串来完成此任务吗?
PS:我已经尝试过 h:mmtt
但正如预期的那样,这并没有给我我想要的东西
Could someone please guide me on the correct format string to display a time in the following format?
Original: #7/28/2011 09:00:03 AM#
Required Format: 9am
//BUT if the minutes part contains a value I want it to look like this
Original: #7/28/2011 09:21:03 AM#
Required Format: 9:21am
Is there one format string I can use to accomplish this?
PS: I have tried h:mmtt
but as expected that doesnt quite give me what I want
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
格式化字符串没有帮助。您想要根据值有条件地格式化字符串。您必须自己检查分钟值,并根据是否有 0 分钟应用适当的格式字符串。
Format strings won't help. You want to conditionally format the string based on a value. You will have to check the minutes value yourself and apply the appropriate format string based on whether there are 0 minutes or not.
您需要编写逻辑来指出 00 条件,只要您发现 00 作为分钟,则仅返回小时值,否则返回小时和分钟值,例如
you need to write logic to stip out the 00 condition where whenever you found 00 as minutes then return only hour value else return hour and minutes values like
尝试一下~
try~