在C#格式化日期/时间 [英] Formatting a Date/Time in C#

查看:149
本文介绍了在C#格式化日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期/时间字符串,看起来像以下内容:

I have a date/time string that looks like the following:

Wed Sep 21 2011 12:35 PM Pacific

我如何格式化日期时间,看起来像这样?

How do I format a DateTime to look like this?

感谢您

推荐答案

时区之前,该位是容易的,使用的custom日期和时间格式字符串

The bit before the time zone is easy, using a custom date and time format string:

string text = date.ToString("ddd MMM dd yyyy hh:mm t");



不过,我相信.NET日期/时间格式化会的的给你太平洋的一部分。它可以给你的最好的是从UTC时区的偏移的。那很好,如果你能得到其他方式的时区名称。

However, I believe that the .NET date/time formatting will not give you the "Pacific" part. The best it can give you is the time zone offset from UTC. That's fine if you can get the time zone name in some other way.

一个数的TimeZoneInfo 标识符包括的字太平洋,但没有一个这只是太平洋。

A number of TimeZoneInfo identifiers include the word Pacific, but there isn't one which is just "Pacific".

这篇关于在C#格式化日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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