C# DateTimeOffset Parse(String)
Description
DateTimeOffset Parse(String)
converts the specified
string representation of a date, time, and offset to its DateTimeOffset
equivalent.
Syntax
DateTimeOffset.Parse(String)
has the following syntax.
public static DateTimeOffset Parse(
string input
)
Parameters
DateTimeOffset.Parse(String)
has the following parameters.
input
- A string that contains a date and time to convert.
Returns
DateTimeOffset.Parse(String)
method returns An object that is equivalent to the date and time that is contained in input.
Example
The following example calls the Parse(String) method to parse several date and time strings.
/*www . j a v a 2 s.c om*/
using System;
public class MainClass{
public static void Main(String[] argv){
string dateString;
DateTimeOffset offsetDate;
// String with date only
dateString = "05/01/2014";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());
// String with time only
dateString = "11:36 PM";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());
// String with date and offset
dateString = "05/01/2014 +1:00";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());
// String with day abbreviation
dateString = "Thu May 01, 2014";
offsetDate = DateTimeOffset.Parse(dateString);
Console.WriteLine(offsetDate.ToString());
}
}
The code above generates the following result.