Internationalization and localization tools


C# Date/Time Formatting

using System

DateTime(long);

DateTime(long ticks, DateTimeKind kind);

DateTime(int year, int month, int day);

DateTime(int year, int month, int day, Calendar calendar);

DateTime(int year, int month, int day, int hour, int minute, int second);

DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar);

DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind);

DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond);

DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar);

DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind);

DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind);

Internationalization (I18n) Class Overview

The DateTime Class provides methods such as DateTime.ToString and DateTime.Parse that allow you to perform culture-sensitive operations on a DateTime object. The DateTimeFormatInfo class defines how DateTime values are formatted and displayed, and is dependent on the culture. For example, using the ShortDatePattern, the date February 1, 2001 is formatted as 2/1/2001 for the "en-US" culture and 01/02/2001 for the "en-GB" culture.

See Microsoft's MSDN online documentation for more information.

I18n Issues

The DateTime class provides seven separate constructor signatures. For proper software internationalization, it is important that developers select a constructor that accepts a Calendar argument, as in the example below. Further, the Calendar object must be retrieved from a CultureInfo object that was instantiated according to the culture of the current user and preferably set in the current thread.

Usage

The following code example displays the current date using the DateTimeFormatInfo.ShortDatePattern when the CurrentThread.CurrentCulture is set to en-US.

            // Create a new instance of DateTime containing the date 
            // 7/28/1979 at 10:35:05 PM using the en-US calendar.
            System.Globalization.CultureInfo info =
            	new System.Globalization.CultureInfo("en-US", false);
            	
            System.Globalization.Calendar calendar = info.Calendar;
            
            System.DateTime dateTime =
            	new System.DateTime(1979, // Year
            		07,         // Month
            		28,         // Day
            		22,         // Hour
            		35,         // Minute
            		5,         // Second
            		15,         // Millisecond
            		calendar   // Calendar
                );
                
            // Write the DateTime as "Saturday, July 28, 1979 10:35:05 PM".
            System.Console.WriteLine("{0:F}", dateTime);
            

General C# date/time formatting information

 

Lingoport internationalization and localization services and software