Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Force the date format to always be en-US

Posted on 2007-11-24
3
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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