Converting between timezones in C -


I need to change time between times in C (on Linux, so anything will be specific).

I know my current time, local and UTC, I have been trying to use mactimes, GMTEM, folktim and similar functions offset of target time, but still understand it not coming.

Thank you in advance.

Do not allow posts to be posted as comments, posting as separate answers. If you know the "local" time and "UTC" time, then you can calculate the offset "other" time from your "local" time and then you convert struct tm to calendar time, the desired seconds Offset offset), and convert it back to the structure tm:

( The normalization of edited Mk time in the account of another scenario for use)

  #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Time.h> # Include & lt; Sys / time.h & gt; Int main (int argc, char * argv) {struct timeline tv_utc; Struct TM * Local_TM, * other_tm; / * 'Synthetic' time_t to convert the structure to TM for other times * / time_t other_t_synt; / * Other time is 1 hour ahead of local time * / int other_lock_delete = 1 * 3600; / * The two lines below are to set local_tm to some * / gettimeofday (& amp; tv_utc, NULL); Local_atom = local time (& amp; tv_utctv_sc); Printf ("Local time:% s", asctime (local_tm)); #ifdef DO_NOT_WRITE_TO_LOCAL_TM other_t_synt = mktime (local_tm) + other_local_delta; #else local_tm-> Tm_sec + = other_local_delta; / * MkTime will normalize the seconds on the correct calendar date * / other_t_synt = mktime (local_tm); #endif other_tm = local time (and other_t_scnt); Printf ("Other times:% s", esketime (other_tm)); Exit (0); }  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -