VC character format to time

Source: Internet
Author: User
// Convert the character format to time. True: add one day; false: minus one day
// Convert the character format to time
Cstring cgrossprofitratioreportdlg: strtodate (cstring strtime, bool baddorplus)
{
Cstring STR (strtime );
Int year, month, day, hour, Minite, second;
Sscanf (STR, "% d-% d: % d", & year, & month, & day, & hour, & Minite, & second );
Coledatetime time (year, month, day, hour, Minite, second );
Coledatetimespan oneday (1); // Time Difference per day
If (baddorplus)
{
Time + = oneday; // the next day
}
Else
{
Time-= oneday; // the previous day
}
Cstring strdate;
Strdate = time. Format ("% Y-% m-% d ");
Return strdate;
}

2.

Cstring STR ("14:00:35 ");
Int nyear, nmonth, nday, nhour, nminite, nsecond;
Sscanf (STR, "% d-% d: % d ",
& Nyear, & nmonth, & nday, & nhour, & nminite, & nsecond );
Ctime time (nyear, nmonth, nday, nhour, nminite, nsecond); top

3.

Use coledatetime, ctime Function Coledatetime has.

Coledatetime oletime1 = coledatetime: getcurrenttime ();
Coledatetime oletime2;
Cstring STR = "12:12:12"
Oletime2.parsedatetime (STR );

If (oletime2> oletime) // coledatetime reloads the comparison operator

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.