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;

CTime T (year,month,day,hour,min,sec);
CTime T1;
t1=t+ (iday-rint) *24*60*60;
return t1;
}

Call
void Cgmtprodlg::onok ()
... {
CTime T1;
708992537 is the number of seconds
T1=getgmtdatetime (708992537);
Char rdate[20]= ... {0};
Char rtime[20]= ... {0};
Isolate date
wsprintf (Rdate, "%04u-%02u-%02u", T1. GetYear (), T1. GetMonth (), T1. Getday ());
Isolate the time
wsprintf (Rtime, "%02u:%02u:%02u", T1. Gethour (), T1. Getminute (), T1. Getsecond ());
Show the date and time.
M_date=rdate;
M_time=rtime;
UpdateData (FALSE);
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.