c# - Convert week and year to milliseconds -
i need convert, title says, weeks , year milliseconds since 1970. best way in .net? have information of week , year event occurred. week stars on monday. think datetime not answer since can't handle week of year. need method double getmili(int week, int year)
. anyway
you can put that:
// let's convert 15th monday in 2014 int mondaysnumber = 15; datetime source = new datetime(2014, 1, 1); int delta = 7 + dayofweek.monday - source.dayofweek; if (delta >= 7) delta -= 7; source = source.adddays((mondaysnumber - 1) * 7 + delta); // finally, convert milliseconds double result = (source - new datetime(1970, 1, 1)).totalmilliseconds;
Comments
Post a Comment