[英]How to get only the date part from Different Time Zone C#
尝试获取其他国家(时区)的日期,然后显示它。 我知道时间和日期。 只需要日期
var info = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
var dateTime = TimeZoneInfo.ConvertTime(DateTime.Now.Date, info);
MessageBox.Show(dateTime.Date.ToString());
需要05/05/2015但不是时间
您可以直接使用
MessageBox.Show(dateTime.ToShortDateString());
否则你可以自定义它
MessageBox.Show(dateTime.ToString("dd/MM/yyyy"));
您只能使用ToShortDateString()
获取date
var info = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
var dateTime = TimeZoneInfo.ConvertTime(DateTime.Now.Date, info);
MessageBox.Show(dateTime.Date.ToShortDateString());
或者你可以直接使用
MessageBox.Show(dateTime.ToShortDateString());
无论如何,您都需要使用一种格式,如果您想指定特定国家/地区的文化,则可以这样做,或者使用DateTime(ToShortDateString(),ToLongDateString()等类中的一种方法)
var ci = new CultureInfo("en-US");
或var ci = CultureInfo.InvariantCulture;
探索CultureInfo了解更多信息
然后使用ToString方法以特定格式获取日期,请参见该格式不包含小时或分钟。
dateTime.ToString("MM/dd/yyyy", provider)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.