版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
POCOC++库学习和分析--日期与时间在Poco库中,与时间和日期相关的一些类,其内部实现是非常简单的。看相关文档时,比较有意思的倒是历史上的不同时间表示法。1.系统时间函数在编程时,时间函数不可避免的会被使用°linux系统下相关时间的数据结构有time_t,timeval,timespec,tm,clock_t;windows下time_t,tm,SYSTEMTIME,clock_t。其中clock_t、timeval、timespec用于表示时间跨度,time_t、tm、SYSTEMTIME用于表示绝对时间。不同的数据结构之间,多少也有些差异。首先这些时间结构体的精度不同,Second(time_t/tm),microsecond(timeval/SYSTEMTIME),nanoSeconds(timespec)。起始时间不同,time_t起始于1970年1月1日0时0分0秒,tm表示起始于1900年,SYSTEMTIME起始于1601年,clock起始于机器开机。同这些数据结构相关联,C语言为tm,time_t提供了一组函数用于时间运算和数据结构转换:[cpp]viewplaincopy//日历时间(一个用time_t表示的整数)2.//比较日历时间doubledifftime(time_ttimel,time_ttime0);//获取日历时间time_ttime(time_t*timer);//转换日历时间为字符串char*ctime(consttime_t*timer);//转换日历时间为我们平时看到的把年月日时分秒分开显示的时间格式tm(GMTtimezone)structtm*gmtime(consttime_t*timer);//转换日历时间为我们平时看到的把年月日时分秒分开显示的时间格式tm(本地timezone)structtm*localtime(consttime_t*timer);//关于本地时间的计算公式:localtime=utctime[Gmttime]+utcOffset()[时区偏移]+dst()[夏令时偏移]15.16.//把tm转换为字符串char*asctime(conststructtm*timeptr);//把tm转换为日历时间time_tmktime(structtm*timeptr);21.22.//获取开机以来的微秒数clock_tclock(void);我们回想一下程序中的时间数据结构和函数的用法,可以发现主要是2个目的:获取绝对时间获取两个时间点的相对时间Timestamp类同C语言中函数类似,Poco中定义了自己的时间类。Timestamp类似于time_t,用于获取比较日历时间。Timestamp定义如下:[cpp]viewplaincopyclassFoundation_APITimestamp{public:Int64TimeVal;///monotonicUTCtimeInt64UtcTimeVal;///monotonicUTCtimeInt64TimeDiff;///differencebetweenvalueinmicrosecondresolutionvaluein100nanosecondresolutiontwotimestampsinmicrosecondstypedeftypedeftypedef5.6.4.valueinmicrosecondresolutionvaluein100nanosecondresolutiontwotimestampsinmicrosecondstypedeftypedeftypedef.9.Timestamp();///Createsatimestampwiththecurrenttime.10.11.12.Timestamp(TimeVal///Createsatv);timestampfromthegiventimevalue.13.14.15.Timestamp(constTimestamp&other);///Copyconstructor.16.17.18.~Timestamp();///Destroysthetimestamp19.20.21.Timestamp&operator=(constTimestamp&other);Timestamp&operator=(TimeValtv);22.23.24.voidswap(Timestamp×tamp);///SwapstheTimestampwithanotherone.25.26.27.void8.9.Timestamp();///Createsatimestampwiththecurrenttime.10.11.12.Timestamp(TimeVal///Createsatv);timestampfromthegiventimevalue.13.14.15.Timestamp(constTimestamp&other);///Copyconstructor.16.17.18.~Timestamp();///Destroysthetimestamp19.20.21.Timestamp&operator=(constTimestamp&other);Timestamp&operator=(TimeValtv);22.23.24.voidswap(Timestamp×tamp);///SwapstheTimestampwithanotherone.25.26.27.voidupdate();///UpdatestheTimestampwiththecurrenttime.28.29.30.bool31.booloperatoroperator32.bool33.booloperatoroperator>=34.bool35.booloperatoroperator(const(const(const(const(const(constTimestamp&ts)Timestamp&ts)Timestamp&ts)Timestamp&ts)Timestamp&ts)Timestamp&ts)const;const;const;const;const;const;37.37.Timestampoperator+(TimeDiffd)const;3.74.75.Timestampoperator-(TimeDifd)const;TimeDif operator-(constTimestamp&ts)const;Timestamp&operator+=(TimeDiffd);Timestamp&operator-=(TimeDifd);std::time_tepochTime()const;///Returnsthetimestampexpressedintime_t.///time_tbasetimeismidnight,January1,1970.///Resolutionisonesecond.UtcTimeValutcTime()const;///ReturnsthetimestampexpressedinUTC-based///time.UTCbasetimeismidnight,October15,1582.///Resolutionis100nanoseconds.TimeValepochMicroseconds()const;///Returnsthetimestampexpressedinmicroseconds///sincetheUnixepoch,midnight,January1,1970.TimeDiffelapsed()const;///Returnsthetimeelapsedsincethetimedenotedby///thetimestamp.EquivalenttoTimestamp()-*this.boolisElapsed(TimeDifinterval)const;///Returnstrueiffthegivenintervalhaspassed///sincethetimedenotedbythetimestamp.staticTimestampfromEpochTime(std::time_tt);///Createsatimestampfromastd::time_t.staticTimestampfromUtcTime(UtcTimeValval);///CreatesatimestampfromaUTCtimevalue.staticTimeValresolution();///Returnstheresolutioninunitspersecond.///Sincethetimestamphasmicrosecondresolution,///thereturnedvalueisalways1000000.private:TimeVal_ts;};Timestamp内部定义了一个Int64的变量_ts。存储了一个基于utc时间的64位int值,理论上可以提供微秒级的精度(实际精度依赖于操作系统)。由于Poco::Timestamp是基于UTC(世界标准时间或世界協調時間)的,所以它是独立于时区设置的。Poco::Timestamp实现了值语义,比较和简单的算术操作。UTC(CoordinatedUniversalTime)是从1582年10月15日深夜开始计时的.Poco库中精度为100纳秒。2.epochtime指是从1970年1月1日深夜开始计时的(指unix诞生元年)。Poco库中精度为1秒。数据类型:Poco::Timestamp内部定义了下列数据类型:TimeVal一个64位的int整数值,保存utc时间,精度微秒UtcTimeVal一个64位的int整数值,保存utc时间,精度100纳秒(真实精度仍然是微秒)TimeDiff一个64位的int整数值,保存两个Timestamp的差值,精度微秒构造函数:默认构造函数会以当前时间初始化一个Timestamp值,基于UTC时间(从1582年10月15日开始计时,精度为100纳秒)提供了两个静态函数用于创建Timestamp对象,TimestampfromEpochTime(time_ttime)。这个函数从time_t构建,内部会把EpochTime(从1970年1月1日深夜开始计时的,精度为1秒)的时间转换成为UTC时间。TimestampfromUtcTime(UtcTimeValval)。这个函数从一个UtcTimeVal构建。Timestamp的成员函数:time_tepochTime()const返回一个以epochtime计算的日历时间(精度秒)。(函数内部会把基于UTC时间的值转为基于epochtime的值)UtcTimeValutcTime()const返回一个以UTC时间计算的日历时间(精度100纳秒)。TimeValepochMicroseconds()const返回一个以epochtime计算的日历时间(精度微秒)voidupdate()取当前的时间更新TimeDiffelapsed()const返回当前时间与Timestamp内部时间_ts的一个时间差值(精度微秒)boolisElapsed(TimeDiffinterval)const如果当前时间与Timestamp内部时间_ts的一个时间差值大于interval时间,返回true。(精度微秒)Timestamp算术计算:Timestampoperator+(TimeDiffdiff)const增加一个时间偏移,并返回值。(精度微秒)Timestampoperator-(TimeDiffdiff)const减掉一个时间偏移,并返回值。(精度微秒)TimeDiffoperator-(constTimestamp&ts)const返回两个Timestamp对象的时间偏移。(精度微秒)Timestamp&operator+=(TimeDiffd)Timestamp&operator-=(TimeDiffd)增加或减小一个时间偏移值下面来看一个例子:[cpp]viewplaincopy#include"Poco/Timestamp.h"#include<ctime>usingPoco::Timestamp;intmain(intargc,char**argv){Timestampnow;//thecurrentdateandtimestd::time_tt1=now.epochTime();//convert totime_t…Timestampts1(Timestamp:fromEpochTime(t1)); //...andback againfor(inti=0;i<100000;++i);//waita bitTimestamp::TimeDiffdif=now.elapsed();// howlongdidit take?Timestampstart(now);//savestarttimenow.update();//updatewithcurrenttimedif=now-start;//again,howlong?return0;}DateTime类Poco中提供了DateTime类,作用和tm类似。下面是它的定义:[cpp]viewplaincopy1.classFoundation_APIDateTime2.{3.public:4.enumMonths5.///Symbolicnamesformonthnumbers(1to12).6.{7.JANUARY=1,8.FEBRUARY,9.MARCH,10.APRIL,11.MAY,12.JUNE,13.JULY,14.AUGUST,15.SEPTEMBER,16.OCTOBER,17.NOVEMBER,
6.DECEMBER};enumDaysOfWeek///Symbolicnamesforweekdaynumbers(0to6).{SUNDAY=0,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};DateTime();///CreatesaDateTimeforthecurrentdateandtime.DateTime(constTimestamp×tamp);///CreatesaDateTimeforthedateandtimegivenin///aTimestamp.DateTime(intyear,intmonth,intday,inthour=0,intminute=0,intsecond=0,intmillisecond=0,intmicrosecond=0);///CreatesaDateTimeforthegivenGregoriandateandtime./// *yearisfrom0to9999./// *monthisfrom1to12./// *dayisfrom1to31./// *hourisfrom0to23.TOC\o"1-5"\h\z/// * minuteisfrom 0to 59./// * secondisfrom 0to 59./// * millisecondis from 0to 999./// * microsecondis from 0to 999.DateTime(doublejulianDay);///CreatesaDateTimeforthegivenJulianday.DateTime(Timestamp::UtcTimeValutcTime,Timestamp::TimeDiffdiff);///CreatesaDateTimefromanUtcTimeValandaTimeDiff.//////MainlyusedinternallybyDateTimeandfriends.DateTime(constDateTime&dateTime);
8. int00013.114.115.///Copyconstructor.CreatestheDateTimefromanotherone.~DateTime();///DestroystheDateTime.DateTime&operator=(constDateTime&dateTime);///AssignsanotherDateTime.DateTime&operator=(constTimestamp×tamp);///AssignsaTimestamp.DateTime&operator=(doublejulianDay);///AssignsaJulianday.DateTime&assign(intyear,intmonth,intday,inthour=0,intminute=0,second=0,intmillisecond=0,intmicroseconds=0);///AssignsaGregoriandateandtime./// *yearisfrom0to9999./// *monthisfrom1to12./// *dayisfrom1to31./// *hourisfrom0to23.TOC\o"1-5"\h\z/// * minuteisfrom 0to 59./// * secondisfrom 0to 59./// * millisecondis from 0to 999./// * microsecondis from 0to 999.voidswap(DateTime&dateTime);///SwapstheDateTimewithanotheryear()const;///Returnsthemonth()const;///Returnsthemonth(1to12).intweek(intfirstDayOfWeek=MONDAY)const;///Returnstheweeknumberwithintheyear.///FirstDayOfWeekshouldbeeitherSUNDAY(0)orMONDAY(1).///Thereturnedweeknumberwillbefrom0to53.Weeknumber1is
theweek///containingJanuary4.ThisisinaccordancetoISO86063.//////ThefollowingexampleassumesthatfirstDayOfWeekisMONDAY.For2005,whichstarted///onaSaturday,week1willbetheweekstartingonMonday,January3.///January1and2willfallwithinweek0(orthelastweekofthepreviousyear).//////For2007,whichstartsonaMonday,week1willbetheweekstartungonMonday,January1.///Tday()const;///Returnsthedaywitinthemonth(1to31).intdayOfWeek()const;///Returnstheweekday(0to6,where///0=Sunday,1=Monday, 6=Saturday).intdayOfYear()const;///Returnsthenumberofthedayintheyear.///January1is1,February1is32,hour()const;///Returnsthehour(0to23).inthourAMPM()const;///Returnsthehour(0to12).boolisAM()const;///Returnstrueifhour<12;boolisPM()const;///Returnstrueifhour>=12.intminute()const;///Returnstheminute(0to59).intsecond()const;///Returnsthesecond(0to59).intmillisecond()const;///Returnsthemillisecond(0to999)intmicrosecond()const;///Returnsthemicrosecond(0to999)
doublejulianDay()const;000012.///Returnsthejuliandayforthedateandtime.Timestamptimestamp()const;///ReturnsthedateandtimeexpressedasaTimestamp.Timestamp::UtcTimeValutcTime()const;///ReturnsthedateandtimeexpressedinUTC-based///time.UTCbasetimeismidnight,October15,1582.///Resolutionis100nanoseconds.booloperator==booloperator!=booloperator<(booloperator==booloperator!=booloperator<(constDateTime&dateTime)const;(constDateTime&dateTime)const;booloperator<=(booloperator<=(constDateTime&dateTime)const;booloperator>booloperator>(constDateTime&dateTime)const;booloperator>=(constDateTime&booloperator>=(constDateTime&dateTime)const;DateTimeoperator+(constTimespan&span)const;DateTimeoperator-(constTimespan&span)const;Timespanoperator-(constDateTimeDateTimeoperator-(constTimespan&span)const;Timespanoperator-(constDateTime&dateTime)const;DateTime&operator+=(constTimespan&span);DateTime&operator-=(constTimespan&span);voidmakeUTC(inttzd);///ConvertsalocaltimeintoUTC,byapplyingthegiventimezonedifferential.voidmakeLocal(inttzd);///ConvertsaUTCtimeintoalocaltime,byapplyingthegiventimezonedifferential.staticboolisLeapYear(intyear);///Returnstrueifthegivenyearisaleapyear;///falseotherwise.staticintdaysOfMonth(intyear,intmonth);///Returnsthenumberofdaysinthegivenmonth///andyear.Monthisfrom1to12.staticboolisValid(intyear,intmonth,intday,inthour=0,intminute=214.0,215.216.intsecond=0,intmillisecond=0,intmicrosecond=0);Checksifthegivendateandtimeisvalid(allargumentsarewithinaproperrange).//////217.///218.///Returnstrueifallargumentsarevalid,falseotherwise.214.0,215.216.intsecond=0,intmillisecond=0,intmicrosecond=0);Checksifthegivendateandtimeisvalid(allargumentsarewithinaproperrange).//////217.///218.///Returnstrueifallargumentsarevalid,falsetected://...222.private:224.//...Timestamp::UtcTimeVal_utcTime;225.Timestamp::UtcTimeVal_utcTime;227.short_year;228.short_month;229.short_day;230.short_hour;231.short_minute;232.short_second;233.short_millisecond;234.short_microsecond;235.};226.Poco::DateTime是基于格里高利历(Gregoriancalendar"就是公历啦)设计的。它除了可以用来保存日历时间外,还可以被用于日期计算。如果只是为了日历时间的存储,Timestamp类更加适合。在DateTime的内部,DateTime类用两种格式维护了日期和时间。第一种是UTC日历时间。第二种是用年、月、日、时、分、秒、微秒、毫秒。为了进行内部时间日期之间的换算,DateTime使用了儒略日(Julianday)历法。格里高利历(Gregoriancalendar)格里高利历就是我们通常讲的公历。它以耶稣的诞生为初始年份,也就是公元0001年。格里高利历以日为基本单位,1年有365或366天,分成12个月,每个月时长不等。由于不同国家采用格里高利历时间不同(德国1582,英国1752),所以格里高利历日期和旧式的日期有差别,即使是用来表示历史上相同的一件事。一个耶稣像,A_Ao_XXXX_/_;-.__/_\_•-;_'、'、/'、_'、\/'|//-.(\_._\\\';>|////|//\(\儒略日和儒略日日期儒略日的起点订在公元前4713年(天文学上记为-4712年)1月1日格林威治时间平午(世界时12:00),即JD0指定为UT时间B.C.4713年1月1日12:00到UC时间B.C.4713年1月2日12:00的24小时。注意这一天是礼拜一。每一天赋予了一个唯一的数字,顺数而下,如:1996年1月1日12:00:00的儒略日是2450084。这个日期是考虑了太阳、月亮的轨道运行周期,以及当时收税的间隔而订出来的。JosephSeliger定义儒略周期为7980年,是因28、19、15的最小公倍数为28x19x15=7980。日期的注意事项:1.0是一个合法数字(根据ISO8691和天文年编号)0年是一个闰年。负数是不支持的。比如说公元前1年。格里高利历同历史上的日期可能不同,由于它们采用的日历方式不同。最好只是用DateTime用来计算当前的时间。对于历史上的或者天文日历的时间计算,还是使用其他的特定软件。构造DateTime:可以从一个已有的DateTime构造当前的时间和日期一个Timestamp对象用年、月、日、时、分、秒、微秒、毫秒构造使用一个儒略日日期构造(用double形式保存)成员函数:intyear()const返回年intmonth()const返回月(1-12)intweek(intfirstDayOfWeek=DateTime::MONDAY)const返回所在的周,根据ISO8601标准(第一周是1月4日所在的周),一周的第一天是礼拜一或者礼拜天。intday()const返回月中的所在天(1-31)intdayOfWeek()const返回周中的所在天0为周日,1为周一■,intdayOfYear()const返回年中的所在天(1-366)inthour()const返回天中所在小时(0-23)inthourAMPM()const返回上下午所在小时(0-12)boolisAM()const如果上午返回真boolisPM()const如果下午返回真intminute()const返回分钟数(0-59)intsecond()const返回秒数(0-59)
intmillisecond。const返回毫秒数(0-999)intmicrosecond。const返回微秒数(0-999)Timestamptimestamp()const返回用Timestamp保存的日历时间(精度微秒)Timestamp::UtcTimeValutcTime()const返回用Timestamp保存的日历时间(精度100纳秒)DateTime支持关系运算符(==,!=,>,>=,<,<=).DateTime支持算术操作(+,-,+=,-=)静态函数:boolisLeapYear(intyear)所给年是否闰年intdaysOfMonth(intyear,intmonth)所给年和月的天数boolisValid(intyear,intmonth,intday,inthour,intminute,intsecond,intmillisecond,intmicrosecond)判断所给年月日是否合法下面是DateTime的一个例子:[cpp]viewplaincopy#include"Poco/DateTime.h"usingPoco::DateTime;intmain(intargc,char**argv){DateTimenow;//thecurrentdateandtimeinUTCintyear=now.year();int month =now.month();int day = now.day();int dow = now.dayOfWeek();int doy = now.dayOfYear();inthour=now.hour();inthour12=now.hourAMPM();int min=now.minute();int sec=now.second();int ms=lisecond();int us=now.microsecond();doublejd=now.julianDay();Poco::Timestampts=now.timestamp();DateTimexmas(2006,12,25);//2006-12-2500:00:00Poco::TimespantimeToXmas=xmas-now;21.22.DateTimedt(1973,9,12,2,30,45);//1973-09-1202:30:45dt.assign(2006,10,13,13,45,12,345);//2006-10-1312:45:12.345boolisAM=dt.isAM();//false
boolisPM=dt.isPM();//trueboolisLeap=DateTime::isLeapYear(2006);//falseintdays=DateTime::daysOfMonth(2006,2);//28boolisValid=DateTime::isValid(2006,02,29);//falsedt.assign(2006,DateTime::OCTOBER,22);//2006-10-2200:00:00if(dt.dayOfWeek()==DateTime::SUNDAY)TOC\o"1-5"\h\z{// ...}return 0;}LocalDateTime类Poco::LocalDateTime同Poco::DateTime类似,不同的是Poco::LocalDateTime存储一个本地时间。关于本地时间和UTC时间有如下计算公式:(UTC时间=本地时间-时区差).构造函数:通过当前时间构造通过Timestamp对象通过年、月、日、时、分、秒、微秒、毫秒构造通过儒略日时间构造(儒略日时间用double存储)作为可选项。时区可作为构造时第一个参数被指定。(如果没有指定的话,会使用系统当前的时区)成员函数:LocalDateTime支持所有的DateTime的函数。在进行比较之前,所有的关系操作符函数会把时间都换算为UTC时间inttzd()const返回时区差DateTimeutc()const转换本地时间到utc时间下面是一个例子:[cpp]viewplaincopy#include"Poco/LocalDateTime.h"usingPoco::LocalDateTime;intmain(intargc,char**argv){LocalDateTimenow;//thecurrentdateandlocaltimeintyear=now.year();int month =now.month();int day = now.day();int dow = now.dayOfWeek();int doy = now.dayOfYear();9.}inthour=now.hour();inthour12=now.hourAMPM();intmin=now.minute();intsec=now.second();intms=lisecond();intus=now.microsecond();inttzd=now.tzd();doublejd=now.julianDay();Poco::Timestampts=now.timestamp();LocalDateTimedt1(1973,9,12,2,30,45);//1973-09-1202:30:45dt1.assign(2006,10,13,13,45,12,345);//2006-10-1312:45:12.345LocalDateTimedt2(3600,1973,9,12,2,30,45,0,0);//UTC+1hourdt2.assign(3600,2006,10,13,13,45,12,345,0);Poco::TimestampnowTS;LocalDateTimedt3(3600,nowTS);//constructfromTimestampreturn0;Timespan类Poco::Timespan能够提供一个微秒精度的时间间隔,也可以用天、小时、分钟、秒、微秒、毫秒来表示。在其内部这个时间间隔用一个64-bit整形来表示。构造函数:一个TimeStamp::TimeDiff对象(微秒精度)秒+微秒主要用于从timeval结构体构建通过日、时、分、秒、微秒构造操作符:Poco::Timespan支持所有的关系操作符(==,!=,v,<=,>,>=)Poco::Timespan支持加法和减法操作(+,-,+=,_=)成员函数:intdays()const返回时间跨度的天inthours()const返回时间跨度的小时(0-23)inttotalHours()const返回时间跨度总的小时数intminutes()const返回时间跨度的分钟(0-59)inttotalMinutes()const返回时间跨度总的分钟数intseconds()const返回时间跨度的秒(0-60)inttotalSeconds()const返回时间跨度总的秒数intmilliseconds()const返回时间跨度的毫秒((0-999)inttotalMilliseconds()const返回时间跨度总的毫秒数intmicroseconds()const返回时间跨度的微秒((0-999)inttotalMicroseconds()const返回时间跨度总的微秒数下面是一个例子:[cpp]viewplaincopy#include"Poco/Timespan.h"usingPoco::Timespan;intmain(intargc,char**argv){Timespants1(1,11,45,22,123433);//1d11h45m22.123433sTimespants2(33*Timespan::SEC0NDS);//33sTimespants3(2*Timespan::DAYS+33*Timespan::HOURS);//3d33hintdays=ts1.days();//1inthours=ts1.hours();//11inttotalHours=ts1.totalHours();//35intminutes=ts1.minutes();//45inttotalMins=ts1.totalMinutes();//2145intseconds=ts1.seconds();//22inttotalSecs=ts1.totalSeconds();//128722return0;}下面来看一个DateTime,LocalDateTime和Timespan的混合例子:[cpp]viewplaincopy#include"Poco/DateTime.h"#include"Poco/Timespan.h"usingPoco::DateTime;usingPoco::Timespan;intmain(intargc,char**argv){//whatismyage?DateTimebirthdate(1973,9,12,2,30);//1973-09-1202:30:00DateTimenow;Timespanage=now-birthdate;
intdays=age.days();//indaysinthours=age.totalHours();//inhoursintsecs=age.totalSeconds(); // inseconds//whenwasI10000daysold?Timespanspan(10000*Timespan::DAYS);DateTimedt=birthdate+span;return0;}Timezone类Poco::Timezone提供静态函数用于获取时区信息和夏令时信息。时区差是否采用夏时制(daylightsavingtime(DST))时区名成员函数:intutcOffset()返回本地时间相对于UTC时间的差值(精度秒)。不包括夏令时偏移:(localtime=UTC+utcOffset())intdst()返回夏令时偏移。通常是固定值3600秒。0的话表示无夏令时。boolisDst(constTimestamp×tamp)对于给定的timestamp时间测试,是否使用夏令时inttzd()返回本地时间相对于UTC时间的差值(精度秒)。包括夏令时偏移:(tzd=utcOffset()+dst())std::stringname()返回当前的时区名std::stringstandardName()返回当前的标准时区名(如果不采用夏令时)std::stringdstName()返回当前的时区名(如果采用夏令时)时区名的返回依赖于操作系统,并且名称不具有移植性,仅作显示用。下面是一个使用的例子:[cpp]viewplaincopy#include"Poco/Timezone.h"#include"Poco/Timestamp.h"usingPoco::Timezone;usingPoco::Timestamp;intmain(intargc,char**argv){intutcOffset=Timezone::utcOffset();intdst=Timezone::dst();
boolisDst=Timezone::isDst(Timestamp());inttzd=Timezone::tzd();std::stringname=Timezone::name();std::stringstdName=Timezone::standardName();std::stringdstName=Timezone::dstName();return0;}6.Poco::DateTimeFormatter类Poco::DateTimeFormatter用来定义当Timestamp,DateTime,LocalDateTimeandTimespan转换为字符串时所需的日期和事件格式。Poco::DateTimeFormatter的作用和strftime()是类似的。Poco::DateTimeFormat内部定义了一些约定的格式。ISO8601_FORMAT(2005-01-01T12:00:00+01:00)RFC1123_FORMAT(Sat,1Jan200512:00:00+0100)SORTABLE_FORMAT(2005-01-0112:00:00)Formoreinformation,pleaseseethereferencedocumentation.成员函数:所有的DateTimeFormatter函数都是静态的。下面是一个使用的例子:[cpp]viewplaincopy#include"Poco/Timestamp.h"#include"Poco/Timespan.h"#include"Poco/DateTimeFormatter.h"#include"Poco/DateTimeFormat.h"usingPoco::DateTimeFormatter;usingPoco::DateTimeFormat;intmain(intargc,char**argv){Poco::DateTimedt(2006,10,22,15,22,34);std::strings(DateTimeFormatter::format(dt,"%e%b%Y%H:%M"));//"22Oct200615:22"Poco::Timestampnow;s=DateTimeFormatter::format(now,DateTimeFormat::SORTABLE_FORMAT);//"2006-10-3009:27:44"Poco::Timespanspan(5, 11,33,0,0);s=DateTimeFormatter::format(span,"%ddays,%Hhours,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026山东青岛市莱西市卫生健康系统招聘卫生类岗位人员135人考试参考试题及答案解析
- 2026年甘肃省天水市麦积区招聘公益性岗位35人考试备考题库及答案解析
- 2026浙江杭州市西湖区申花路幼儿园招聘3人(非事业)考试参考试题及答案解析
- 2026河南郑州中牟人才集团招聘软件架构师、智能网联测试员6人考试参考题库及答案解析
- 2026山东拓普液压气动有限公司招聘5人考试备考试题及答案解析
- 2026云南大理州第二人民医院招聘4人考试参考试题及答案解析
- 2026重庆建工集团工程管理中心招聘4人笔试参考题库及答案解析
- 2026湖北武汉市江汉区金融类国企招聘2人考试备考试题及答案解析
- 2026贵州安顺市西秀区安大学校春季学期临聘教师招聘2人考试参考题库及答案解析
- 2026贵州黔南州荔波县人力资源和社会保障局招聘城镇公益性岗位人员6人考试备考试题及答案解析
- 节后复工启动部署课件
- 2026年安全生产开工第一课筑牢复工复产安全防线
- 2026年标准版离婚协议书(无财产)
- 山西大学附属中学2025-2026学年高三1月月考生物(含答案)
- 2024年货车驾驶员管理制度
- 信息保密协议书(标准版)
- 2024年10月自考中国近现代史纲要试题真题及答案
- 2025年同等学力申硕英语真题及参考答案A卷
- 汽轮机组启停操作相关试验
- 2025年中医新专长考试题库
- 三年级数学下册口算练习题(每日一练共12份)
评论
0/150
提交评论