I am currently using NodaTime to parse dates and output dates
public static string nodaTimeTest6(string input)
{
var defaultValue = new OffsetDateTime(new LocalDateTime(2000, 1, 1, 0, 0), Offset.Zero);
var pattern = OffsetDateTimePattern.Create("yyyy-MM-dd'T'HH:mm:sso<m>", CultureInfo.InvariantCulture, defaultValue);
var result = pattern.Parse(input);
return result.Value.Month + "/" + result.Value.Day + "/" + result.Value.Year + " " + result.Value.ClockHourOfHalfDay;
}
The input, for example, is this: 2014-03-11T02:00:00-07:00
If my return
statement is the following: return result.Value.ToString()
, then the output would look like this: 2014-03-11T02:00:00-07
I understand the use of properties with NodaTime (which is a life saver), however, I am interested in outputs like this:
yyyy-MM-dd HH:mm:ss
yyyyMMdd HH:mm:ss
dd/MM/yyyy hh:mm
So I tried to change my return
statement to this:
return result.Value.Month + "/" + result.Value.Day + "/" + result.Value.Year + " " + result.Value.Hour + ":" + result.Value.Minute;
The final output of that format is: 3/11/2014 2:0
Is there anyway to craft the output so it's a fixed format like 03/11/2014 02:00
I know that if I input an 01
as my month, the output would be 1/11/2014
instead of 01/11/2014
You can send the format to the ToString
method:
return result.Value.ToString("dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments