DateTime Format Example


Date Formatted Based on Culture Example

using System; using System.Globalization;

namespace DateTimeFormatExample

{

class Program

{     static void Main(string[] args)

{       //This example is going to show how to format

// a date for several cultures. We could pick

// any date for this example, but just for kicks

// we’ll pick December 21, 2012. This date is

// mysterious to astrologists and conspiracy

// theorists because it is the end of the Mayan

// calandar… will it be THE end? Who knows, but

// we’ll use it here for our example.

// Declare the date December 21, 2012

DateTime dt = new DateTime(2012, 12, 21, 4, 0, 0);

//First let’s print out for US English

CultureInfo en_us_ci = new CultureInfo(“en-US”);

//Print short date format

Console.WriteLine(“US English ” + dt.ToString(“d”, en_us_ci));

//Next let’s print out for Chinese, PRC

CultureInfo zh_cn_ci = new CultureInfo(“zh-CN”);

Console.WriteLine(“Chinese, PRC ” + dt.ToString(“d”, zh_cn_ci));

//Next let’s print out for German (Germany)

CultureInfo de_de_ci = new CultureInfo(“de-DE”);

Console.WriteLine(“German (Germany) ” + dt.ToString(“d”, de_de_ci));

//Next let’s print out for Hebrew (Israel)

CultureInfo he_il_ci = new CultureInfo(“he-IL”);

Console.WriteLine(“Hebrew (Israel) ” + dt.ToString(“d”, he_il_ci));

//Next let’s print out for Punjabi (India)

CultureInfo pa_in_ci = new CultureInfo(“pa-IN”);

Console.WriteLine(“Punjabi (India) ” + dt.ToString(“d”, pa_in_ci));

}

}

}

Date Format Example Output US English 12/21/2012 Chinese, PRC 2012/12/21 German (Germany) 21.12.2012 Hebrew (Israel) 21/12/2012 Punjabi (India) 21-12-12

Additional Resources CultureInfo Class (Microsoft) – http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx

Advertisements

About sharepointsriram

9+ Yrs of IT experience
Gallery | This entry was posted in Sharepoint 2010 Server Object Model. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s