c# - Inconsistent DateTime to Unix Time conversion and error on 24 hour input -


attached method using takes in list of datetime strings, input format (i.e. yyyy-mm-dd hh:mm:ss), , offset in form of hours.

as culture , "standard", using invariantculture , converting times utc.

    public int unixformat3(string datetimeinput, string inputformat, int hours)     {         datetime result;         cultureinfo provider = cultureinfo.invariantculture;         result = datetime.parseexact(datetimeinput, inputformat, provider);          int unixtime = (int32)(result.touniversaltime().addhours(hours).subtract(new datetime(1970, 1, 1, 0, 0, 0, 0, system.datetimekind.utc))).totalseconds;         return unixtime;     } 

two issues said method:

  1. i using website comparison. if input 2014-03-18 21:00:00, output, according method, 1395190800, converts 2014-03-19 01:00:00. has 4 hour difference. desired output this:

enter image description here

  1. if input 2014-03-18 24:00:00, error:

the datetime represented string not supported in calendar system.globalization.gregoriancalendar.

noticeably, not allow input of 24 in hh part. weird error nodatime handles fine... though that's irrelevant using datetime.

does have insight on area?

edit:

upon experimentation, removing .touniversaltime() removes 4-hour offset.. why happening?

public int unixformat3(string datetimeinput, string inputformat, int hours) {     datetime result;     cultureinfo provider = cultureinfo.invariantculture;     result = datetime.parseexact(datetimeinput, inputformat, provider);      int unixtime = (int32)(result.addhours(hours).subtract(new datetime(1970, 1, 1, 0, 0, 0, 0, system.datetimekind.utc))).totalseconds;     return unixtime; } 

this document, http://www.w3.org/tr/note-datetime, cited in question how know whether given string valid utc datetime format? not list 24 valid hour value.

this document, http://en.wikipedia.org/wiki/iso8601, cited answer question list 24:00 valid time. one, http://en.wikipedia.org/wiki/12-hour_clock#confusion_at_noon_and_midnight, says 24:00 valid.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -