Create DateTime from year, month, day, hour, minute, second, millisecond at Coordinated Universal Time (UTC) or local time for specified calendar in CSharp
Description
The following code shows how to create DateTime from year, month, day, hour, minute, second, millisecond at Coordinated Universal Time (UTC) or local time for specified calendar.
Example
using System;//w w w .j av a 2 s .c o m
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;
public class Example
{
public static void Main()
{
PersianCalendar persian = new PersianCalendar();
DateTime date1 = new DateTime(1389, 5, 27, 16, 32, 18, 500,
persian, DateTimeKind.Local);
Console.WriteLine("{0:M/dd/yyyy h:mm:ss.fff tt} {1}", date1, date1.Kind);
Console.WriteLine("{0}/{1}/{2} {3}{8}{4:D2}{8}{5:D2}.{6:G3} {7}\n",
persian.GetMonth(date1),
persian.GetDayOfMonth(date1),
persian.GetYear(date1),
persian.GetHour(date1),
persian.GetMinute(date1),
persian.GetSecond(date1),
persian.GetMilliseconds(date1),
date1.Kind,
DateTimeFormatInfo.CurrentInfo.TimeSeparator);
}
}
The code above generates the following result.