How to convert from UTC to local time in C?

If you can assume POSIX (and thus the POSIX specification of time_t as seconds since the epoch), I would first use the POSIX formula to convert to seconds since the epoch: tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 + (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 – ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 Next, use localtime((time_t []){0}) to get a struct tm … Read more

LocalDateTime to java.sql.Date in java 8?

There is no direct correlation between LocalDateTime and java.sql.Date, since former is-a timestamp, and latter is-a Date. There is, however, a relation between LocalDate and java.sql.Date, and conversion can be done like this: LocalDate date = //your local date java.sql.Date sqlDate = java.sql.Date.valueOf(date) Which for any given LocalDateTime gives you the following code: LocalDateTime dateTime … Read more

Convert DateTime for MySQL using C#

Keep in mind that you can hard-code ISO format string formatForMySql = dateValue.ToString(“yyyy-MM-dd HH:mm:ss”); or use next: // just to shorten the code var isoDateTimeFormat = CultureInfo.InvariantCulture.DateTimeFormat; // “1976-04-12T22:10:00” dateValue.ToString(isoDateTimeFormat.SortableDateTimePattern); // “1976-04-12 22:10:00Z” dateValue.ToString(isoDateTimeFormat.UniversalSortableDateTimePattern) and so on

How to check if DST (Daylight Saving Time) is in effect, and if so, the offset?

This code uses the fact that getTimezoneOffset returns a greater value during Standard Time versus Daylight Saving Time (DST). Thus it determines the expected output during Standard Time, and it compares whether the output of the given date the same (Standard) or less (DST). Note that getTimezoneOffset returns positive numbers of minutes for zones west … Read more