Csharp/CSharp Tutorial/Date Time/DateTime Parse ParseExact
Содержание
- 1 DateTime.Parse: M
- 2 DateTime.ParseExact: (PM, h:mm:ss tt, null)
- 3 DateTime.ParseExact: Mon, 05 SepMT, ddd, dd MMM yyyy HH":"mm":"ss "GMT", null
- 4 DateTime.ParseExact: September 05, MMMM dd, null
- 5 DateTime.Parse: Monday 5 September16:31
- 6 DateTime.Parse: Sep 2005
- 7 Use the Parse() method to convert strings to DateTime instances: 4
DateTime.Parse: M
using System;
class MainClass
{
public static void Main(string[] args)
{
DateTime dt5 = DateTime.Parse("2:15 PM");
Console.WriteLine(dt5);
}
}
25/03/2007 2:15:00 PM
==DateTime.Parse: /td>
using System;
class MainClass
{
public static void Main(string[] args)
{
DateTime dt3 = DateTime.Parse("5,9,05");
Console.WriteLine(dt3);
}
}
05/09/2005 12:00:00 AM
==DateTime.Parse: /td>
using System;
class MainClass
{
public static void Main(string[] args)
{
DateTime dt4 = DateTime.Parse("5/9/2005 14:15:33");
Console.WriteLine(dt4);
}
}
05/09/2005 2:15:33 PM
DateTime.ParseExact: (PM, h:mm:ss tt, null)
using System;
class MainClass
{
public static void Main(string[] args)
{
DateTime dt6 = DateTime.ParseExact("2:13:30 PM", "h:mm:ss tt", null);
Console.WriteLine(dt6);
}
}
25/03/2007 2:13:30 PM
DateTime.ParseExact: Mon, 05 SepMT, ddd, dd MMM yyyy HH":"mm":"ss "GMT", null
using System;
class MainClass
{
public static void Main(string[] args)
{
DateTime dt7 = DateTime.ParseExact("Mon, 05 Sep 2005 14:13:30 GMT", "ddd, dd MMM yyyy HH":"mm":"ss "GMT"", null);
Console.WriteLine(dt7);
}
}
05/09/2005 2:13:30 PM
DateTime.ParseExact: September 05, MMMM dd, null
using System;
class MainClass
{
public static void Main(string[] args)
{
DateTime dt8 = DateTime.ParseExact("September 05", "MMMM dd", null);
Console.WriteLine(dt8);
}
}
05/09/2007 12:00:00 AM
DateTime.Parse: Monday 5 September16:31
using System;
class MainClass
{
public static void Main(string[] args)
{
DateTime dt2 = DateTime.Parse("Monday 5 September 2005 14:16:31");
Console.WriteLine(dt2);
}
}
05/09/2005 2:16:31 PM
DateTime.Parse: Sep 2005
using System;
class MainClass
{
public static void Main(string[] args)
{
// 1st September 2005 00:00:00
DateTime dt1 = DateTime.Parse("Sep 2005");
Console.WriteLine(dt1);
}
}
01/09/2005 12:00:00 AM
Use the Parse() method to convert strings to DateTime instances: 4
using System;
class MainClass
{
public static void Main()
{
DateTime myDateTime5 = DateTime.Parse("1/11/2004");
Console.WriteLine("myDateTime5 = " + myDateTime5);
}
}
myDateTime5 = 01/11/2004 12:00:00 AM
==Use the Parse() method to convert strings to DateTime instances: /td>
using System;
class MainClass
{
public static void Main()
{
DateTime myDateTime5 = DateTime.Parse("1/11/2004 23:10:30");
Console.WriteLine("myDateTime5 = " + myDateTime5);
}
}
myDateTime5 = 01/11/2004 11:10:30 PM