0

I am working on an application which have 2 language versions. In this app I am creating a DateTime object for 1st day of the month. e.g. DateTime startOfMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

The output comes out as;

11/1/2013 12:00:00 AM

in english version

However in french version it comes out as The culture becomes 'fr-CA' in this case

11/1/2013 00:00:00

Can anyone help me in getting value similar to english version ? With string.Format this can be achieved but I need DateTime object not string.

Thanks in advance.

VJOY
  • 3,752
  • 12
  • 57
  • 90

2 Answers2

0

Take a look here

http://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx

Something like this should work

date1.ToString("MM/dd/yy H:mm:ss zzz")
javram
  • 2,635
  • 1
  • 13
  • 18
  • I don't want it to be string, but DateTime object – VJOY Nov 29 '13 at 04:46
  • in the example code I provided, date1 is of type System.DateTime. In order to send to the console or output to the screen, you must create a string representation of the date object. – javram Nov 29 '13 at 04:54
0

To custom format your date object, format it with 12 hour time. As you can see in english version it is showing date in 12 hour format and in french version it is showing date in 24 hour format. So format it like:

date.ToString("MM/dd/yyyy hh:mm:ss tt");

or

date.ToString("M/d/yyyy h:m:s tt");
Nitin Joshi
  • 1,638
  • 1
  • 14
  • 17