| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> zai C yu yan zhong ru he chu li shi jian he ri qi

zai C yu yan zhong ru he chu li shi jian he ri qi

2008-06-01 02:07:10 编辑來源:互联网 评论
 
 
 
本文为【在C语言中如何处理时间和日期】的拼音翻译版
  ChUCk Allison shi yan hu cheng sheng Latter Day jiao tang zong bu xia ye su jiao tang jia zu li shi yan jiu chu de ruan jian ti xi she ji shi 。 ta yong you shu xue xue shi he shu xue shuo shi xue wei 。 ta cong 1975 nian qi kai shi bian cheng , cong 1984 nian qi ta kai shi cong shi c yu yan de jiao xue he kai fa 。 ta mu qian de ai hao shi mian xiang dui xiang de ji shu ji qi jiao yu 。 ta shi X3J16,ANSI C ++ biao zhun hua wei yuan hui de yi yuan 。
  da bu fen de cao zuo xi tong you ban fa de dao dang qian de ri qi he shi jian 。 tong guo ding yi zai time.h de ku han shu ,ANSI C neng yi xu duo bu tong de xing shi de dao zhe ge xin xi 。 han shu time fan hui yi ge lei xing wei time_t de zhi ( tong chang wei long), gai han shu zai yun xing qi jian dui dang qian de ri qi he shi jian jin xing bian ma 。 ran hou ni ke yi jiang zhe ge fan hui zhi chuan di gei qi ta neng dui gai zhi jin xing jie ma he ge shi hua de han shu 。
  Listing 1 zhong de cheng xu shi yong han shu time,localtime he strftime yi bu tong de xing shi shu chu dang qian de ri qi he shi jian 。 han shu localtime ba yi jing bian ma de shi jian jie ma cheng ru xia de struct:
  struct tm
  {
  int tm_sec; /* (0 - 61) */
  int tm_min; /* (0 - 59) */
  int tm_hour; /* (0 - 23) */
  int tm_mday; /* (1 - 31) */
  int tm_mon; /* (0 - 11) */
  int tm_year; /* past 1900 */
  int tm_wday; /* (0 - 6) */
  int tm_yday; /* (0 - 365) */
  int tm_isdst; /* daylight savings flag */
  };
  mei ci dang ni tiao yong localtime de shi hou , ta hui chong xie yi ge jing tai de jie gou bing fan hui gai jie gou de di zhi ( yin ci tong yi shi ke zai yi ge cheng xu zhong zhi neng qu de yi ge zhe yang de jie gou , er bu neng zuo ming xian de kao bei )。 han shu ctime fan hui yi ge zhi xiang jing tai zi fu chuan de zhi zhen , gai zi fu chuan yi biao zhun de ge shi bao han le wan zheng de shi jian he ri qi 。strftime gen ju yong hu de zhi ding ge shi ge shi hua zi fu chuan ( li ru ,%A dai biao yi zhou zhong mei yi tian de ming cheng )。Table 1 lie chu le ge shi miao shu fu de wan zheng lie biao 。
  shi jian / ri qi yun suan
  tong guo gai bian tm jie gou li de zhi , ke dui shi jian / ri qi jin xing yun suan 。Listing 2 zhong de cheng xu zhan shi le ru he ji suan jiang lai mou tian de ri qi he yi miao wei dan wei suo ji suan chu de cheng xu zhi xing shi jian 。 zhu chong han shu time de yu fa ( shen shu time_t you di zhi chuan ru , bing fei zuo wei han shu de fan hui zhi )。 han shu mktime gai bian tm jie gou de zhi , yi bian ri qi he shi jian zai yi ge he shi de fan wei nei , zhi hou day-of-week (tm_wday) he day-of-year (tm_yday) yu jin xing xiang ying de geng xin 。mktime jiang tm jie gou zhong ri qi he shi jian de zhi zhi yu he shi de fan wei zhi nei , xiang ying de geng xin day of week (tm-wday) he day of year (tm-yday) de zhi 。 zhe zhong qing kuang fa sheng zai dang yi ge ri qi chao chu le ni de shi xian neng gou zhi chi de fan wei de shi hou 。 li ru , wo de MS-DOS de bian yi qi bu neng bian ma 1970 nian 1 yue fen zhi qian de ri qi 。 han shu asctime fan hui tm shen shu suo miao shu shi jian de biao zhun zi fu chuan ( yin ci ctime (&tval) yu asctime (localtime(&tval) shi xiang deng de )。 han shu difftime fan hui yong miao zuo dan wei de liang ge time_t de cha 。
  jia ru xu yao chu li chao chu xi tong fan wei de ri qi , huo zhe xu yao ji suan liang ge ri qi de jian ge you bu shi yong miao lai zuo dan wei , na ni xu yao she ji zi ji de date bian ma 。Listing 3 dao Listing 5 zhong de ying yong cheng xu tong guo shi yong yi ge jian dan de month-day-year jie gou , zhan shi le que ding liang ge ri qi jian ge de nian shu 、 yue fen shu he tian shu de ji shu 。 ri qi de xiang jian jiu xiang ni zai xiao xue li zuo de jian fa na yang ( li ru , shou xian jin xing tian shu de xiang jian , jia ru xu yao jiu xiang yue fen shu jie wei , yi ci lei tui )。 zhu chong tiao guo de nian fen dou bei ji suan jin qu le 。 wei le jian lue qi jian ,date_interval han shu jia she ri qi dou shi you xiao de , bing qie di yi ge ri qi zai di er ge ri qi zhi qian 。 han shu fan hui yi ge zhi xiang jing tai Date jie gou de zhi zhen , gai jie gou bao han le wo men xiang yao de da an 。
  wen jian shi jian / ri qi chuo
  da duo shu cao zuo xi tong wei wen jian wei hu shi jian / ri qi chuo 。 zhi shao ni neng de zhi yi ge wen jian zui hou bei xiu gai de shi jian 。( chang yong de make gong ju shi yong zhe yi xin xi lai jue ding yi ge wen jian shi fou xu yao bei chong xin bian yi , huo zhe yi ge ying yong cheng xu shi fou xu yao bei chong xin lian jie )。 you yu wen jian xi tong zai bu tong ping tai shang you suo bu tong , mei you shen me tong yong de han shu de dao yi ge wen jian de shi jian / ri qi chuo , yin ci ANSI biao zhun mei you ding yi zhe yang de han shu 。 ran er , da duo shu liu xing de cao zuo xi tong ( bao kuo MS-DOS he VAX/VMS) ti gong le UNIX han shu stat, gai han shu fan hui xiang guan de wen jian xin xi , bao kuo yong time_t biao shi de zui hou xiu gai shi jian 。
  Listing 6 zhong de cheng xu shi yong stat he difftime lai que ding shi fou time1.c bi time2.c geng xin ( li ru , shi fou zui jin bei xiu gai guo )。
  jia ru ni xu yao geng xin yi ge wen jian de shi jian / ri qi chuo dao dang qian shi jian , ke jian dan de chong xie wen jian de di yi ge zi jie 。 sui ran shi ji nei rong bing wei gai bian , dan ni de wen jian xi tong hui ren wei wen jian yi jing bei gai bian le , bing qie hui xiang ying de geng xin shi jian / ri qi chuo 。( zhi dao ni de wen jian xi tong ! zai VAX/VMS xia , dang ni de dao yi ge wen jian de xin ban ben de shi hou , jiu de ban ben reng hui bei bao liu )。 zhe zhong ji shu jiao zuo "''touching'' yi ge wen jian "。Listing 7 zhong touch de shi xian zai zhi ding wen jian bu cun zai de shi hou hui chuang jian yi ge xin wen jian 。 zhu chong wen jian yi "binary" mo shi da kai ( zai da kai mo shi zi fu chuan zhong you zi fu b jue ding - zai jiang lai de zhuan lan zhong wo hui ju ti tao lun wen jian chu li de wen ti )。 biao 1:strftime de ge shi miao shu fu
  Code Sample Output
  ---------------------------------------------
  %a Wed
  %A Wednesday
  %b Oct
  %B October
  %c Wed Oct 07 13:24:27 1992
  %d 07 (day of month [01-31])
  %H 13 (hour in [00-23])
  %I 01 (hour in [01-12])
  %j 281 (day of year [001-366])
  %m 10 (month [01-12])
  
   %M 24 (minute [00-59])
  %p PM
  27 (second [00-59] )
  %U 40 (Sunday week of year [00-52])
  %w 3 (day of week [0-6])
  %W 40 (Monday week of year [00-52])
  %x Wed Oct 7, 1992
  %X 13:24:27
  %y 92
  %Y 1992
  %Z EDT (daylight savings indicator)【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
 ChUCk Allison shi yan hu cheng sheng Latter Day jiao tang zong bu xia ye su jiao tang jia zu li shi yan jiu chu de ruan jian ti xi she ji shi 。 ta yong you shu xue xue shi he shu xue shuo shi xue wei 。 ta cong 1975 nian qi kai shi bian cheng , cong 1984 nian qi ta kai shi cong shi c yu yan de jiao xue he kai fa 。 ta mu qian de ai hao shi mian xiang dui xiang de ji shu ji qi jiao yu 。 ta shi X3J16,ANSI C ++ biao zhun hua wei yuan hui de yi yuan 。    da bu fen de cao zuo xi tong you ban fa de dao dang qian de ri qi he shi jian 。 tong guo ding yi zai time.h de ku han shu ,ANSI C neng yi xu duo bu tong de xing shi de dao zhe ge xin xi 。 han shu time fan hui yi ge lei xing wei time_t de zhi ( tong chang wei long), gai han shu zai yun xing qi jian dui dang qian de ri qi he shi jian jin xing bian ma 。 ran hou ni ke yi jiang zhe ge fan hui zhi chuan di gei qi ta neng dui gai zhi jin xing jie ma he ge shi hua de han shu 。   Listing 1 zhong de cheng xu shi yong han shu time,localtime he strftime yi bu tong de xing shi shu chu dang qian de ri qi he shi jian 。 han shu localtime ba yi jing bian ma de shi jian jie ma cheng ru xia de struct: struct tm {  int tm_sec; /* (0 - 61) */  int tm_min; /* (0 - 59) */  int tm_hour; /* (0 - 23) */  int tm_mday; /* (1 - 31) */  int tm_mon; /* (0 - 11) */  int tm_year; /* past 1900 */  int tm_wday; /* (0 - 6) */  int tm_yday; /* (0 - 365) */  int tm_isdst; /* daylight savings flag */ };    mei ci dang ni tiao yong localtime de shi hou , ta hui chong xie yi ge jing tai de jie gou bing fan hui gai jie gou de di zhi ( yin ci tong yi shi ke zai yi ge cheng xu zhong zhi neng qu de yi ge zhe yang de jie gou , er bu neng zuo ming xian de kao bei )。 han shu ctime fan hui yi ge zhi xiang jing tai zi fu chuan de zhi zhen , gai zi fu chuan yi biao zhun de ge shi bao han le wan zheng de shi jian he ri qi 。strftime gen ju yong hu de zhi ding ge shi ge shi hua zi fu chuan ( li ru ,%A dai biao yi zhou zhong mei yi tian de ming cheng )。Table 1 lie chu le ge shi miao shu fu de wan zheng lie biao 。    shi jian / ri qi yun suan    tong guo gai bian tm jie gou li de zhi , ke dui shi jian / ri qi jin xing yun suan 。Listing 2 zhong de cheng xu zhan shi le ru he ji suan jiang lai mou tian de ri qi he yi miao wei dan wei suo ji suan chu de cheng xu zhi xing shi jian 。 zhu chong han shu time de yu fa ( shen shu time_t you di zhi chuan ru , bing fei zuo wei han shu de fan hui zhi )。 han shu mktime gai bian tm jie gou de zhi , yi bian ri qi he shi jian zai yi ge he shi de fan wei nei , zhi hou day-of-week (tm_wday) he day-of-year (tm_yday) yu jin xing xiang ying de geng xin 。mktime jiang tm jie gou zhong ri qi he shi jian de zhi zhi yu he shi de fan wei zhi nei , xiang ying de geng xin day of week (tm-wday) he day of year (tm-yday) de zhi 。 zhe zhong qing kuang fa sheng zai dang yi ge ri qi chao chu le ni de shi xian neng gou zhi chi de fan wei de shi hou 。 li ru , wo de MS-DOS de bian yi qi bu neng bian ma 1970 nian 1 yue fen zhi qian de ri qi 。 han shu asctime fan hui tm shen shu suo miao shu shi jian de biao zhun zi fu chuan ( yin ci ctime (&tval) yu asctime (localtime(&tval) shi xiang deng de )。 han shu difftime fan hui yong miao zuo dan wei de liang ge time_t de cha 。    jia ru xu yao chu li chao chu xi tong fan wei de ri qi , huo zhe xu yao ji suan liang ge ri qi de jian ge you bu shi yong miao lai zuo dan wei , na ni xu yao she ji zi ji de date bian ma 。Listing 3 dao Listing 5 zhong de ying yong cheng xu tong guo shi yong yi ge jian dan de month-day-year jie gou , zhan shi le que ding liang ge ri qi jian ge de nian shu 、 yue fen shu he tian shu de ji shu 。 ri qi de xiang jian jiu xiang ni zai xiao xue li zuo de jian fa na yang ( li ru , shou xian jin xing tian shu de xiang jian , jia ru xu yao jiu xiang yue fen shu jie wei , yi ci lei tui )。 zhu chong tiao guo de nian fen dou bei ji suan jin qu le 。 wei le jian lue qi jian ,date_interval han shu jia she ri qi dou shi you xiao de , bing qie di yi ge ri qi zai di er ge ri qi zhi qian 。 han shu fan hui yi ge zhi xiang jing tai Date jie gou de zhi zhen , gai jie gou bao han le wo men xiang yao de da an 。    wen jian shi jian / ri qi chuo    da duo shu cao zuo xi tong wei wen jian wei hu shi jian / ri qi chuo 。 zhi shao ni neng de zhi yi ge wen jian zui hou bei xiu gai de shi jian 。( chang yong de make gong ju shi yong zhe yi xin xi lai jue ding yi ge wen jian shi fou xu yao bei chong xin bian yi , huo zhe yi ge ying yong cheng xu shi fou xu yao bei chong xin lian jie )。 you yu wen jian xi tong zai bu tong ping tai shang you suo bu tong , mei you shen me tong yong de han shu de dao yi ge wen jian de shi jian / ri qi chuo , yin ci ANSI biao zhun mei you ding yi zhe yang de han shu 。 ran er , da duo shu liu xing de cao zuo xi tong ( bao kuo MS-DOS he VAX/VMS) ti gong le UNIX han shu stat, gai han shu fan hui xiang guan de wen jian xin xi , bao kuo yong time_t biao shi de zui hou xiu gai shi jian 。   Listing 6 zhong de cheng xu shi yong stat he difftime lai que ding shi fou time1.c bi time2.c geng xin ( li ru , shi fou zui jin bei xiu gai guo )。    jia ru ni xu yao geng xin yi ge wen jian de shi jian / ri qi chuo dao dang qian shi jian , ke jian dan de chong xie wen jian de di yi ge zi jie 。 sui ran shi ji nei rong bing wei gai bian , dan ni de wen jian xi tong hui ren wei wen jian yi jing bei gai bian le , bing qie hui xiang ying de geng xin shi jian / ri qi chuo 。( zhi dao ni de wen jian xi tong ! zai VAX/VMS xia , dang ni de dao yi ge wen jian de xin ban ben de shi hou , jiu de ban ben reng hui bei bao liu )。 zhe zhong ji shu jiao zuo "''touching'' yi ge wen jian "。Listing 7 zhong touch de shi xian zai zhi ding wen jian bu cun zai de shi hou hui chuang jian yi ge xin wen jian 。 zhu chong wen jian yi "binary" mo shi da kai ( zai da kai mo shi zi fu chuan zhong you zi fu b jue ding - zai jiang lai de zhuan lan zhong wo hui ju ti tao lun wen jian chu li de wen ti )。 biao 1:strftime de ge shi miao shu fu Code Sample Output --------------------------------------------- %a Wed %A Wednesday %b Oct %B October %c Wed Oct 07 13:24:27 1992 %d 07 (day of month [01-31]) %H 13 (hour in [00-23]) %I 01 (hour in [01-12]) %j 281 (day of year [001-366]) %m 10 (month [01-12]) %M 24 (minute [00-59]) %p PM 27 (second [00-59] ) %U 40 (Sunday week of year [00-52]) %w 3 (day of week [0-6]) %W 40 (Monday week of year [00-52]) %x Wed Oct 7, 1992 %X 13:24:27 %y 92 %Y 1992 %Z EDT (daylight savings indicator)
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
桌球宝贝_性感在蔓延(3)
桌球宝贝_性感在蔓延(2)
银杏树下清纯女孩(9)
银杏树下清纯女孩(8)
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有