Solved

Force the date format to always be en-US

Posted on 2007-11-24
3
242 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
Comment Utility
0
 
LVL 55

Expert Comment

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

0
 
LVL 29

Expert Comment

by:Göran Andersson
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

10 Experts available now in Live!

Get 1:1 Help Now