Conversion between C ++ datetime and string

Source: Internet
Author: User
Conversion between C ++ datetime and string

VC6

Cstring stime = _ T ("13:20:30 ");

Char * chartime = (lpstr) (lpctstr) stime;

Cstring sformat = _ T ("% d-% d: % d ");

Char * charformat = (lpstr) (lpctstr) sformat;

Int nyear;

Int nmonth;

Int ndate;

Int nhour;

Int Nmin;

Int nsec;

Stscanf (chartime, charformat, & nyear, & nmonth, & ndate, & nhour, & Nmin, & nsec );

Ctime T (nyear, nmonth, ndate, nhour, Nmin, nsec );

Cstring S = T. Format (_ T ("% Y % m month % d % H % m minute % s second "));

VC2005

Chinese format not included

Stscanf (chartime, charformat, & nyear, & nmonth, & ndate, & nhour, & Nmin, & nsec );

Cstring stime = _ T ("12:40:10 ");

Tchar * chartime = (tchar *) (lpctstr) stime;

CString sFormat = _ T ("% d-% d: % d ");

TCHAR * charFormat = (TCHAR *) (LPCTSTR) sFormat;

Int nYear;

Int nMonth;

Int nDate;

Int nHour;

Int nMin;

Int nSec;

_ Stscanf (charTime, charFormat, & nYear, & nMonth, & nDate, & nHour, & nMin, & nSec );

CTime t (nYear, nMonth, nDate, nHour, nMin, nSec );

CString s = t. Format (_ T ("% Y-% m-% d % H: % M: % S "));

Chinese format

To include # include <locale. h>

CString sTime = _ T ("12:40:10 ");

TCHAR * charTime = (TCHAR *) (LPCTSTR) sTime;

CString sFormat = _ T ("% d-% d: % d ");

TCHAR * charFormat = (TCHAR *) (LPCTSTR) sFormat;

Int nYear;

Int nMonth;

Int nDate;

Int nHour;

Int nMin;

Int nSec;

_ Stscanf (charTime, charFormat, & nYear, & nMonth, & nDate, & nHour, & nMin, & nSec );

CTime t (nYear, nMonth, nDate, nHour, nMin, nSec );

_ Tsetlocale (LC_ALL, _ T ("Chinese-simplified"); // localized

CString s = t. Format (_ T ("% Y % m month % d % H % M minute % S second "));

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.