C++ 的 get_time 和 put_time 函数

为了快速的时间格式转换. C++ 引进了 get_time 和 put_time 函数

#include <iostream>
#include<iomanip>
#include<ctime>
int main()
{
std::time_t t = std::time(NULL);
std::tm tm = *std::localtime(&t);
std::cout.imbue(std::locale("CHS"));
std::cout <<std::put_time(&tm,"%Y-%m-%d %H:%M:%S") << '\n';
// std::cout.imbue(std::locale("ja_JP.utf8"));
// std::cout << "ja_JP: " << std::put_time(&tm, "%c %Z") << '\n';
system("pause");
}

下面是时间函数格式串的一些特定转义参数:
注::VS2010 不支持C++11的格式

E前缀的表示在当地语言环境中的表示...
O前缀的表示使用当地语言环境的计数文字

常用

时:分:秒 %H:%M:%S <==> %T (C++11标准)
当地时间标准 %X
十二小时制 %I (%p <==> a.m|p.m 或者当地写法)

年-月-日 %Y:%m:%d <==> %F (C++11标准)
当期日期标准 %x 
一年的第几天 %j
第几周 %U (00-53) 周日为第一天
%W (00-53) 周一为第一天
%V (01-53) 周一为第一天 (C++11标准)
周一为星期的第一天
每年的第一星期为包含1月4号的那个星期.
或者包含第一个星期四那个星期
星期几 %w (0-6) %u(1-7)(C++11标准)
星期几 %a 单词简写 %A 单词全称 (当地写法)

Conversion
specifier
Explanation Used fields
%writes literal %. The full conversion specification must be %%. 
n(C++11)writes newline character 
t(C++11)writes horizontal tab character 
Year
Ywrites year as a 4 digit decimal number XXXX 4位数年份tm_year
EY(C++11)writes year in the alternative representation, e.g.平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP localetm_year
ywrites last 2 digits of year as a decimal number ( XX range [00,99]两位数年份tm_year
Oy(C++11)writes last 2 digits of year using the alternative numeric system, e.g. 十一 instead of 11 in ja_JP localetm_year
Ey(C++11)writes year as offset from locale's alternative calendar period %EC (locale-dependent)tm_year
C(C++11)writes first 2 digits of year as a decimal number (range [00,99]公历年的前两位数tm_year
EC(C++11)writes name of the base year (period) in the locale's alternative representation, e.g. 平成 (Heisei era) in ja_JPtm_year
G(C++11)writes ISO 8601 week-based year, i.e. the year that contains the specified week.

In IS0 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:

  • Includes January 4
  • Includes first Thursday of the year
tm_year,tm_wday,tm_yday
g(C++11)writes last 2 digits of ISO 8601 week-based year, i.e. the year that contains the specified week (range[00,99]).

In IS0 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:

  • Includes January 4
  • Includes first Thursday of the year
tm_year,tm_wday,tm_yday
Month
bwrites abbreviated month name, e.g. Oct (locale dependent) 月份英文简称tm_mon
h(C++11)synonym of 代名词?tm_mon
Bwrites full month name, e.g. October (locale dependent) 月份英文全称tm_mon
mwrites month as a decimal number (range [01,12]月份两位数字tm_mon
Om(C++11)writes month using the alternative numeric system, e.g. 十二 instead of 12 in ja_JP locale月份当地文字tm_mon
Week
Uwrites week of the year as a decimal number (Sunday is the first day of the week) (range[00,53]第几周(周日为第一天)tm_year,tm_wday,tm_yday
OU(C++11)writes week of the year, as by %U, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP localetm_year,tm_wday,tm_yday
Wwrites week of the year as a decimal number (Monday is the first day of the week) (range[00,53]第几周(周一为第一天)tm_year,tm_wday,tm_yday
OW(C++11)writes week of the year, as by %W, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP localetm_year,tm_wday,tm_yday
V(C++11)writes ISO 8601 week of the year (range [01,53]).

In IS0 8601 weeks begin with Monday and the first week of the year must satisfy the following requirements:

  • Includes January 4
  • Includes first Thursday of the year
tm_year,tm_wday,tm_yday
OV(C++11)writes week of the year, as by %V, using the alternative numeric system, e.g. 五十二 instead of 52 in ja_JP localetm_year,tm_wday,tm_yday
Day of the year/month
jwrites day of the year as a decimal number (range [001,366]一年的第几天(XXX)tm_yday
dwrites day of the month as a decimal number (range [01,31]一月的第几天(XX)tm_mday
Od(C++11)writes zero-based day of the month using the alternative numeric system, e.g 二十七 instead of 23 in ja_JP locale

Single character is preceded by a space.

tm_mday
e(C++11)writes day of the month as a decimal number (range [1,31]).

Single digit is preceded by a space.一月的第几天(X|XX)

tm_mday
Oe(C++11)writes one-based day of the month using the alternative numeric system, e.g. 二十七 instead of 27 in ja_JP locale

Single character is preceded by a space.

tm_mday
Day of the week
awrites abbreviated weekday name, e.g. Fri (locale dependent) 星期几的简写tm_wday
Awrites full weekday name, e.g. Friday (locale dependent) 星期几的全称tm_wday
wwrites weekday as a decimal number, where Sunday is 0 (range [0-6]星期几数字表示(0-6)tm_wday
Ow(C++11)writes weekday, where Sunday is 0, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP localetm_wday
u(C++11)writes weekday as a decimal number, where Monday is 1 (ISO 8601 format) (range [1-7]星期几数字表示(1-7)tm_wday
Ou(C++11)writes weekday, where Monday is 1, using the alternative numeric system, e.g. 二 instead of 2 in ja_JP localetm_wday
Hour, minute, second
Hwrites hour as a decimal number, 24 hour clock (range [00-23]24进制小时(XX)tm_hour
OH(C++11)writes hour from 24-hour clock using the alternative numeric system, e.g. 十八 instead of 18 in ja_JP localetm_hour
Iwrites hour as a decimal number, 12 hour clock (range [01,12]12进制小时(XX)tm_hour
OI(C++11)writes hour from 12-hour clock using the alternative numeric system, e.g. 六 instead of 06 in ja_JP localetm_hour
Mwrites minute as a decimal number (range [00,59]分钟(XX)tm_min
OM(C++11)writes minute using the alternative numeric system, e.g. 二十五 instead of 25 in ja_JP localetm_min
Swrites second as a decimal number (range [00,60]秒数(XX)- -|有60秒耶tm_sec
OS(C++11)writes second using the alternative numeric system, e.g. 二十四 instead of 24 in ja_JP localetm_sec
Other
cwrites standard date and time string, e.g. Sun Oct 17 04:41:13 2010(locale dependent) 基本日期格式all
Ec(C++11)writes alternative date and time string, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP localeall
xwrites localized date representation (locale dependent)all
Ex(C++11)writes alternative date representation, e.g. using 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP localeall
Xwrites localized time representation (locale dependent)all
EX(C++11)writes alternative time representation (locale dependent)all
D(C++11)equivalent to "%m/%d/%y"tm_mon,tm_mday,tm_year
F(C++11)equivalent to "%Y-%m-%d" (the ISO 8601 date format)tm_mon,tm_mday,tm_year
r(C++11)writes localized 12-hour clock time (locale dependent)tm_hour,tm_min,tm_sec
R(C++11)equivalent to "%H:%M"tm_hour,tm_min
T(C++11)equivalent to "%H:%M:%S" (the ISO 8601 time format)tm_hour,tm_min,tm_sec
pwrites localized a.m. or p.m. (locale dependent)tm_hour
z(C++11)writes offset from UTC in the ISO 8601 format (e.g. -0430), or no characters if the time zone information is not availabletm_isdst
Zwrites time zone name or abbreviation, or no characters if the time zone information is not available (locale dependent)tm_isdst


以下 为 std::get_time 一些转义参数
Conversion
specifier
Explanation Writes to fields
%matches a literal %. The full conversion specification must be %%.(none)
tmatches any whitespace.(none)
nmatches any whitespace.(none)
Year
Yparses full year as a 4 digit decimal number, leading zeroes permitted but not requiredtm_year
EYparses year in the alternative representation, e.g.平成23年 (year Heisei 23) which writes 2011 to tm_year in ja_JP localetm_year
yparses last 2 digits of year as a decimal number. Range [69,99] results in values 1969 to 1999, range [00,68] results in 2000-2068tm_year
Oyparses last 2 digits of year using the alternative numeric system, e.g. 十一 is parsed as 11 in ja_JP localetm_year
Eyparses year as offset from locale's alternative calendar period %ECtm_year
Cparses the first 2 digits of year as a decimal number (range [00,99])tm_year
ECparses the name of the base year (period) in the locale's alternative representation, e.g. 平成 (Heisei era) in ja_JPtm_year
Month
bparses the month name, either full or abbreviated, e.g. Octtm_mon
hsynonym of btm_mon
Bsynonym of btm_mon
mparses the month as a decimal number (range [01,12]), leading zeroes permitted but not requiredtm_mon
Omparses the month using the alternative numeric system, e.g. 十二 parses as 12 in ja_JP localetm_mon
Week
Uparses the week of the year as a decimal number (Sunday is the first day of the week) (range[00,53]), leading zeroes permitted but not requiredtm_year,tm_wday,tm_yday
OUparses the week of the year, as by %U, using the alternative numeric system, e.g. 五十二 parses as 52 in ja_JP localetm_year,tm_wday,tm_yday
Wparses the week of the year as a decimal number (Monday is the first day of the week) (range[00,53]), leading zeroes permitted but not requiredtm_year,tm_wday,tm_yday
OWparses the week of the year, as by %W, using the alternative numeric system, e.g. 五十二 parses as 52 in ja_JP localetm_year,tm_wday,tm_yday
Day of the year/month
jparses day of the year as a decimal number (range [001,366]), leading zeroes permitted but not requiredtm_yday
dparses the day of the month as a decimal number (range [01,31]), leading zeroes permitted but not requiredtm_mday
Odparses the day of the month using the alternative numeric system, e.g 二十七 parses as 23 in ja_JP locale, leading zeroes permitted but not requiredtm_mday
esynonym of dtm_mday
Oesynonym of Odtm_mday
Day of the week
aparses the name of the day of the week, either full or abbreviated, e.g. Fritm_wday
Asynonym of atm_wday
wparses weekday as a decimal number, where Sunday is 0 (range [0-6])tm_wday
Owparses weekday as a decimal number, where Sunday is 0, using the alternative numeric system, e.g. 二 parses as 2 in ja_JP localetm_wday
Hour, minute, second
Hparses the hour as a decimal number, 24 hour clock (range [00-23]), leading zeroes permitted but not requiredtm_hour
OHparses hour from 24-hour clock using the alternative numeric system, e.g. 十八 parses as 18 in ja_JP localetm_hour
Iparses hour as a decimal number, 12 hour clock (range [01,12]), leading zeroes permitted but not requiredtm_hour
OIparses hour from 12-hour clock using the alternative numeric system, e.g. 六 reads as 06 in ja_JP localetm_hour
Mparses minute as a decimal number (range [00,59]), leading zeroes permitted but not requiredtm_min
OMparses minute using the alternative numeric system, e.g. 二十五 parses as 25 in ja_JP localetm_min
Sparses second as a decimal number (range [00,60]), leading zeroes permitted but not requiredtm_sec
OSparses second using the alternative numeric system, e.g. 二十四 parses as 24 in ja_JP localetm_sec
Other
cparses the locale's standard date and time string format, e.g. Sun Oct 17 04:41:13 2010 (locale dependent)all
Ecparses the locale's alternative date and time string format, e.g. expecting 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP localeall
xparses the locale's standard date representationall
Exparses the locale's alternative date representation, e.g. expecting 平成23年 (year Heisei 23) instead of 2011年 (year 2011) in ja_JP localeall
Xparses the locale's standard time representationall
EXparses the locale's alternative time representationall
Dequivalent to "%m / %d / %y "tm_mon,tm_mday,tm_year
rparses locale's standard 12-hour clock time (in POSIX, "%I : %M : %S %p")tm_hour,tm_min,tm_sec
Requivalent to "%H : %M"tm_hour,tm_min
Tequivalent to "%H : %M : %S"tm_hour,tm_min,tm_sec
pparses the locale's equivalent of a.m. or p.m.tm_hour

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
所有的 C / C++ 函数 Constructors (cppstring) Constructors (cppvector) Operators (cppbitset) Operators (cppdeque) Operators (cppstack) Operators (cppstring) Operators (cppvector) abort (stdother) abs (stdmath) acos (stdmath) any (cppbitset) append (cppstring) asctime (stddate) asin (stdmath) assert (stdother) assign (cppdeque) assign (cpplist) assign (cppstring) assign (cppvector) at (cppdeque) at (cppstring) at (cppvector) atan (stdmath) atan2 (stdmath) atexit (stdother) atof (stdstring) atoi (stdstring) atol (stdstring) back (cppdeque) back (cpplist) back (cppqueue) back (cppvector) bad (cppio) begin (cppdeque) begin (cpplist) begin (cppmap) begin (cppmultimap) begin (cppmultiset) begin (cppset) begin (cppstring) begin (cppvector) bsearch (stdother) c_str (cppstring) calloc (stdmem) capacity (cppstring) capacity (cppvector) ceil (stdmath) clear (cppdeque) clear (cppio) clear (cpplist) clear (cppmap) clear (cppmultimap) clear (cppmultiset) clear (cppset) clear (cppvector) clearerr (stdio) clock (stddate) compare (cppstring) copy (cppstring) cos (stdmath) cosh (stdmath) count (cppbitset) count (cppmap) count (cppmultimap) count (cppmultiset) count (cppset) ctime (stddate) data (cppstring) #define (preproc) difftime (stddate) div (stdmath) empty (cppdeque) empty (cpplist) empty (cppmap) empty (cppmultimap) empty (cppmultiset) empty (cpppriorityqueue) empty (cppqueue) empty (cppset) empty (cppstack) empty (cppstring) empty (cppvector) end (cppdeque) end (cpplist) end (cppmap) end (cppmultimap) end (cppmultiset) end (cppset) end (cppstring) end (cppvector) eof (cppio) equal_range (cppmap) equal_range (cppmultimap) equal_range (cppmultiset) equal_range (cppset) erase (cppdeque) erase (cpplist) erase (cppmap) erase (cppmultimap) erase (cppmultiset) erase (cppset) erase (cppstring) erase (cppvector) #error (preproc) exit (stdother) exp (stdmath) fabs (stdmath) fail (cppio)
关于c语言和c++的课程成绩信息管理系统,共有将近6000行代码,建议使用vs2012或2010便于管理也可使用VC6.0++环境修改运行但查找麻烦,所有的语言没有脱离c和c++,主要采用模块思想,也可以转换成面向对象型的语言,只要将模块函数写进类中。同时学c语言的也可以使用,除了使用cout,cin一些很容易上手的c++代码,相当于printf,scanf,主要为了方便输入输出,不用写%d%c... 详细细节也可以访问,百度文库网址 使用注意事项 有着强大的报错功能。 1 全部采用鼠标点击功能,可以看百度网址图片。 2 录用学生信息的细节选项中,如果点击错误信息,再次点击将会取消。 3 附加功能中的高级打印功能中,如果想改变选项,只需要点击另一个即可,当前的状态就会消失。 4 输入学号为53120101--531215**(其中不包括****00,例如53120700)。(可以设置) 5 所有成绩范围为0--99。(可以设置) 6 如果想去掉钢琴曲,直接删除MP3,或者改成其他名字即可。 7 打印直方图可以根据班级的不同,向后移动。 7 如果打印不规范,可能窗口较小,可通过调节窗口大小来打印排名...... 8 请包含student.txt默认文件(文件中至少一名学生信息),否则将会程序在进行实质功能作用时意外退出(已在包中)。 头文件student.h #ifndef _STUDENT_H_ #define _STUDENT_H_ #include #include HWND hWnd; //来自msdn #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);} void cls( HANDLE hConsole ) { COORD coordScreen = { 0, 0 }; /* here's where we'll home thecursor */ BOOL bSuccess; DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ DWORD dwConSize; /* number of character cells inthe current buffer *//* get the number of character cells in the current buffer */ bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); PERR( bSuccess, "GetConsoleScreenBufferInfo" ); dwConSize = csbi.dwSize.X * csbi.dwSize.Y;/* fill the entire screen with blanks */ bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten ); PERR( bSuccess, "FillConsoleOutputCharacter" );/* get the current text attribute */ bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); PERR( bSuccess, "ConsoleScreenBufferInfo" );/* now set the buffer's attributes accordingly */ bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ); PERR( bSuccess, "FillConsoleOutputAttribute" );/* put the cursor at (0, 0) */ bSuccess = SetConsoleCursorPosition( hConsole, coordScreen ); PERR( bSuccess, "SetConsoleCursorPosition" ); return; } HANDLE hOut; HANDLE hIn; void enter(); void ReadFile(char*str="student.txt"); typedef enum grade{you=95,liang=85,zhong=75,pass=65,nopass=0 } Grade; Grade g1=you; Grade g2=liang; Grade g3=zhong; Grade g4=pass; Grade g5=nopass; void DelClass(); //学生类结构 typedef struct student{ int studentid; char name[20]; char sex[5]; char nation[20]; int biryear; int birmonth; char post[10]; int cyu; int cyushe; int cshe; int cdui; int cduishe; struct student* next; double ave; double wave; } Student; Student *stubegin=NULL; Student* stulast=NULL; int total=0; //课程类结构 typedef struct course{ char obj[30]; int time; int xuefen; int mark; Grade rank; } Course; Course c1; Course c2; Course c3; Course c4; Course c5; void InitCourse(); void AddData(Student*); void AltData(); void AddShuju(int *,Student*); void IntEro(int& ,int,int,int,int); //功能介绍 /*****************************************Loading页面*******************************************/ void input();//输入信息功能 void output();//输出信息功能 void addition();//附加功能 /*****************************************输入信息功能*******************************************/ void AddStudent(); void DelStudent(int); void AltStudent(int); void SaveMessage(); void readfile(); /*****************************************输出信息功能*******************************************/ void CalRankAve(int); void CalRankWave(int); void PrintStudent(int); void PrintCourse(int); void PrintWell(); /*****************************************打印总成绩*******************************************/ void PrintTotal(); void PrintStudentID(); void PrintAve(); void PrintWave(); /*****************************************打印科目成绩*******************************************/ void PrintObj(); void PrintCyu(); void PrintCyushe(); void PrintCshe(); void PrintCdui(); void PrintCuishe(); /*****************************************打印优秀职务单科成绩*******************************************/ void PrintObjYou(); void PrintCyuYou(); void PrintCyusheYou(); void PrintCsheYou(); void PrintCduiYou(); void PrintCuisheYou(); /*********************辅助函数**********************/ void printmark(Student *); void AddStudent1(); void SortAve(); void SortWave(); void SortId(); void SortCyu(); void SortCyushe(); void SortCshe(); void SortCdui(); void SortCduishe(); int GetInt(char* ); int Search(int); void PrintGrade(int); int GetXuefen(int,int); /****计算平均成绩和加权成绩**/ void CalAve(Student*); void CalWave(Student*); /*****************************************附加功能*******************************************/ void PrintHistogram(); void PrintTotalHistogram();

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值