博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
时间函数
阅读量:4300 次
发布时间:2019-05-27

本文共 3010 字,大约阅读时间需要 10 分钟。

      (1)struct tm *gmtime(const time_t *timep);     

    将日历时间timep转换为用UTC时间表示的时间。它可能返回NULL,比如年份不能放到一个整数中。返回值指向一个静态分配的结构,该结构可能会被接下来的任何日期和时间函数调用覆盖。gmtime_r()函数功能与此相同,但是它可以数据存储到用户提供的结构体中。

            (2)struct tm *localtime(const time_t *clock);

      localtime是 把从1970-1-1零点零分到当前时间系统所偏移的秒数时间转换为本地时间,而gmtime函数转换后的时间没有经过时区变换,是UTC时间 。多线程应用里面,应该用localtime_r函数替代localtime函数,因为localtime_r是线程安全的。

 

    注:日历时间,是用“从一个标准时间点到此时的时间经过的秒数”来表示的时间。这个标准时间点对不同的来说会有所不同,但对一个来说,这个标准时间点是不变的,该编译系统中的时间对应的日历时间都通过该标准时间点来衡量,所以可以说日历时间是“相对时间”,但是无论你在哪一个时区,在同一时刻对同一个标准时间点来说,日历时间都是一样的。在C语言中通过time函数获得日历时间。

   (3)time_t mktime(struct tm * timeptr);

    mktime()用来将参数timeptr所指的tm结构数据转换成从公元1970年1月1日0时0分0 秒算起至今的UTC时间所经过的秒数(带有时区转换,要求timeptr指向的结构是当地时间)。

    由于mktime()要求传入的参数为本地时间,在转换中会先将本地时间转换为GMT时间,再转换为time_t表示的时间,因此认为mktime()带有时区转换.

From MSDN:

       The mktime function converts the supplied time structure(possibly incomplete)pointed to by timeptrinto a fully defined structure with normalized valuesand then converts it to atime_t calendar time value. For description oftm structure fields, see. The converted time has the same encoding as the values returned by thetime function. The original values of the tm_wday andtm_yday components of thetimeptr structure are ignored, and the original values of the other components are not restricted to their normal ranges.

      Note thatgmtime and localtime use a single statically allocated buffer for the conversion. If you supply this buffer tomktime, the previous contents are destroyed.

       Linux 下 man mktime:

       The mktime()function interprets the input structure according to the current time zone setting.

 

   (4)time_t _mkgmtime( struct tm*timeptr);

    Converts a UTC time represented by atm struct to a UTC time represented by atime_t type. (没有时区转换,但要求timeptr指向的数据是UTC时间)

     _mkgmtime()要求传入的参数为GMT时间,在进行时间转换时不会进行时区转换。

  (5)time_t time( time_t *timer);

    MSDN:Gets the system time.

    取系统时间可能受系统中设置的时区影响,因此不是UTC时间。

  (6)

size_t strftime( char *strDest, size_tmaxsize, const char *format, const struct tm *timeptr);

size_t wcsftime( wchar_t *strDest, size_tmaxsize, const wchar_t *format, const struct tm *timeptr);

%a

Abbreviated weekday name

%A

Full weekday name

%b

Abbreviated month name

%B

Full month name

%c

Date and time representation appropriate for locale

%d

Day of month as decimal number (01 – 31)

%H

Hour in 24-hour format (00 – 23)

%I

Hour in 12-hour format (01 – 12)

%j

Day of year as decimal number (001 – 366)

%m

Month as decimal number (01 – 12)

%M

Minute as decimal number (00 – 59)

%p

Current locale’s A.M./P.M. indicator for 12-hour clock

%S

Second as decimal number (00 – 59)

%U

Week of year as decimal number, with Sunday as first day of week (00 – 53)

%w

Weekday as decimal number (0 – 6; Sunday is 0)

%W

Week of year as decimal number, with Monday as first day of week (00 – 53)

%x

Date representation for current locale

%X

Time representation for current locale

%y

Year without century, as decimal number (00 – 99)

%Y

Year with century, as decimal number

%z, %Z

Time-zone name or abbreviation; no characters if time zone is unknown

%%

Percent sign

 

 

 

 

转载地址:http://ajxws.baihongyu.com/

你可能感兴趣的文章
学习笔记_vnpy实战培训day06
查看>>
Python super钻石继承
查看>>
回测引擎代码分析流程图
查看>>
Excel 如何制作时间轴
查看>>
股票网格交易策略
查看>>
matplotlib绘图跳过时间段的处理方案
查看>>
vnpy学习_04回测评价指标的缺陷
查看>>
ubuntu终端一次多条命令方法和区别
查看>>
python之偏函数
查看>>
vnpy学习_06回测结果可视化改进
查看>>
读书笔记_量化交易如何建立自己的算法交易01
查看>>
设计模式03_工厂
查看>>
设计模式04_抽象工厂
查看>>
设计模式05_单例
查看>>
设计模式06_原型
查看>>
设计模式07_建造者
查看>>
设计模式08_适配器
查看>>
设计模式09_代理模式
查看>>
设计模式10_桥接
查看>>
设计模式11_装饰器
查看>>