Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, September 18, 2012 10:56 AM
Hi.
I am getting the datetime value 9/18/2012 15:51:21.
Now I want show the Time value in format AM/PM (i.e. 3:15 PM) either our system in en-US or es-ES using C#.
Regards
Ravi Shankar
All replies (7)
Tuesday, September 18, 2012 1:19 PM ✅Answered
check this out hope this is useful to you
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh965451.aspx
Mark it as helpful if so!!! thanks, Mithilesh
Thursday, September 20, 2012 12:12 PM ✅Answered
You can use DateTimeFormatInfo of System.Globalization.
See below code :
using System.Globalization;
string strDate = @"9/18/2012 15:51:21";
DateTimeFormatInfo dtinfo = new DateTimeFormatInfo();
dtinfo.ShortDatePattern = "MM/dd/yyyy HH:MM TT";
DateTime resultDate = Convert.ToDateTime(dateStrings, dtinfo);
Regards,
Bhushan Shah
Tuesday, September 18, 2012 11:04 AM
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
DateTime dateGregorian = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day);
regards
joon
Tuesday, September 18, 2012 11:11 AM
How about this:
DateTime.Now.ToString("hh:mm tt");
Tuesday, September 18, 2012 11:25 AM
But when your system switches to Spanish the result will be 2:00 instead of 2:00 PM.
Ravi Shankar
Tuesday, September 18, 2012 11:39 AM
Check this
CultureInfo provider = CultureInfo.CreateSpecificCulture("en-US");string dateStrings = @"9/18/2012 15:51:21" ;DateTime result = DateTime.Parse(dateStrings, provider);
With Thanks and Regards
Sambath Raj.C
click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
Happy Programming!
Tuesday, September 18, 2012 12:27 PM
This code is running fine with the Desktop application.
But not with the metro style apps with C#.
Ravi Shankar