c++ - libssh2 remote file attributes last modification time with wrong timezone -


i using libssh2 on linux c++.

i intent see last modification time before downloading file sftp.

to that, use commands:

libssh2_sftp_attributes attrs; libssh2_sftp_fstat_ex(sftp_handle, &attrs, 0); 

i last modiciation time attrs.mtime, long type gives seconds.

however, value timezone gmt+0. how time local timezone?

thank you.

c standard library support timezone conversion functions awful. in short can following assuming tzname variable set correctly.

struct tm tm_utc; gmtime_r(&attrs.mtime, &tm_utc);  // converts epoch time_t utc struct.    time_t local_time = mktime(&tm_utc);  // converts time struct time_t in local time.  printf("local timezone %s, difference %ld\n", *tzname, attrs.mtime - local_time); 

please note mktime calls tzset internally , uses timezone information translating time right timezone. tzset reads tz environment variable , how system knows timezone use.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -