简体   繁体   English

如何在C#中获取系统时间格式,而不是系统时间

[英]how to get system time format in c#,not system time

I need to get the system time format . 我需要获取系统时间格式 If the time in system is in dd/mm/yy format,then I need to create a message box to change the time format to mm/dd/yy .. 如果系统中的时间为dd / mm / yy格式,那么我需要创建一个消息框以将时间格式更改为mm / dd / yy ..

Thanks in advance 提前致谢

For date 对于日期

string dateFormate = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

For time 为了时间

string timeFormate = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;

Try this 尝试这个

using System.Globalization;

...
...
...

var systemDateFormat = CultureInfo.CurrentCulture.DateTimeFormat;

var timePattern = systemDateFormat.FullDateTimePattern;

If you want to detect the format of date and time set for current instance you can use following method. 如果要检测当前实例设置的日期和时间格式,可以使用以下方法。

using System.Globalization;

.

var systemFormat = CultureInfo.CurrentCulture.DateTimeFormat;

var CurrentSystemDateTimePatttern= systemFormat.FullDateTimePattern;

But if you are looking for you own custom format regardless of system format you can use following method... 但是,如果您正在寻找自己的自定义格式,而不考虑系统格式,则可以使用以下方法...

DateTime.Now.ToString("MM/dd/yyyy") // Where MM is Month, dd is day and yyyy is Year in 4 Digit.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM