?
Solved

Force the date format to always be en-US

Posted on 2007-11-24
3
Medium Priority
?
255 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

Independent Software Vendors: 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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 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