convert GMT seconds to date time format-vc++ source code.
Source: Internet
Author: User
Recently in the Writing PE analysis tool, need to convert timedatestamp field value for date time format, this is VC + + source.
Converts the number of seconds in GMT time to date time format
CTime getgmtdatetime (Long Value)
... {
GMT time starting from January 1, 1970, first as the initial value of the assignment
int year=1970, month=1, Day=1;
int hour=0, min=0, sec=0, msec=0;
Temporary variable
int iyear=0, iday=0;
int ihour=0, imin=0, isec=0;
Calculate the year the file was created
Iyear=value/(365*24*60*60);
Year=year+iyear;
How many days to calculate a file except to create an entire year
iday= (Value% (365*24*60*60))/(24*60*60);
Calculate the number of years in a leap year
int rint=0;
for (int i=1970;i<year;i++)
... {
if ((i% 4) ==0)
rint=rint+1;
}
Calculate when the file was created (when)
Ihour= ((Value% (365*24*60*60))% (24*60*60))/(60*60);
Hour=hour+ihour;
Calculated file creation time (in minutes)
Imin= ((Value% (365*24*60*60))% (24*60*60))% (60*60))/60;
Min=min+imin;
Calculate how long a file was created (seconds)
Isec= ((Value% (365*24*60*60))% (24*60*60))% (60*60))% 60;
Sec=sec+isec;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.