Is it possible to pick the phone set time format for a wp7 application
I would like to pick the time format specified in the device (24-hr or 12-hr)开发者_JS百科 to use the same in the application that I develop. Is it possible to do so in WP7?
If you simply use the ToString
method on a DateTime
it will automatically use whatever format the user has specified. The problem comes if you want to customize the format slightly. The following code does hours and minutes using 24-hr/12-hr according to the device setting:
string modified = CultureInfo
.CurrentCulture
.DateTimeFormat
.LongTimePattern
.Replace(":ss", "");
string dateFormat = string.Format("{{0}}, {{1:{0}}}", modified);
string formattedTime = DateTime.Now.ToString(dateFormat);
精彩评论