Solved

Force the date format to always be en-US

Posted on 2007-11-24
3
248 Views
Last Modified: 2013-12-16
Hi,

I need to force the date format to always display it  in en-US format... Since I'm not using en-US as default on my machine, I'm getting the date displayed in another format.

What I exactly need is:

1. Displaying dateTime.ToShortDateString() in en-US format.
2. Displaying dateTime.ToShortTimeString() in fr-FR format.

Below is the code I'm using. How can I modify it?

Thanks a lot.
// This is an example of a UNIX timestamp for the date/time 11-04-2005 09:25.

double timestamp = 1113211532;
 

// First make a System.DateTime equivalent to the UNIX Epoch.

System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
 

// Add the number of seconds in UNIX timestamp to be converted.

dateTime = dateTime.AddSeconds(timestamp);
 

// The dateTime now contains the right date/time so to format the string,

// use the standard formatting methods of the DateTime object.

string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString();
 

// Print the date and time

System.Console.WriteLine(printDate);

Open in new window

0
Comment
Question by:EEssam
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 20343867
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20343897
use:
string printDate = dateTime.ToString("F", new CultureInfo("en-US"));

0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20343942
ToShortDateString uses the "d" format string and ToShortTimeString uses the "t" format string, so you want to do like this:

CultureInfo us = new CultureInfo("en-US");
CultureInfo fr = new CultureInfo("fr-FR");
string printDate = dateTime.ToString("d", us) +" "+ dateTime.ToString("t", fr);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now