zoukankan      html  css  js  c++  java
  • strptime和strptime函数理解

    #include <stdio.h>

           #include <time.h>

           int main() {

                   struct tm tm;

                   char buf[255];

                   strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);

                   strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);

                   puts(buf);

                   return 0;

           }

    这两个函数都是时间日期的格式控制函数,在功能上看起来正好相反。

    size_t strftime(char *s,size_t maxsize,char *format,const struct tm *timeptr)

    作用:strftime将一个tm结构格式化为一个字符串

    参数:format为输出数据格式

    char *strptime(const char *buf,const char *format,struct tm *timeptr)

    作用:strptime则是将一个字符串格式化为一个tm结构。

    参数:buf为要修改的时间,一般为GPS时间

           Format为数据格式,与buf时间格式必须一致,要不然会有段错误

    %a

    星期几的简写形式

    %A

    星期几的全称

    %b

    月份的简写形式

    %B

    月份的全称

    %c

    日期和时间

    %d

    月份中的日期,0-31

    %H

    小时,00-23

    %I

    12进制小时钟点,01-12

    %j

    年份中的日期,001-366

    %m

    年份中的月份,01-12

    %M

    分,00-59

    %p

    上午或下午

    %S

    秒,00-60

    %u

    星期几,1-7

    %w

    星期几,0-6

    %x

    当地格式的日期

  • 相关阅读:
    存储过程3前台
    最简单Login程序
    存储过程前台2
    程序员 开发工具箱
    存储过程4前台
    存储过程 insert
    公司网络解决方案
    存储过程前台
    linux常用指令
    ReentrantLock源码解析3优先响应中断的lockInterruptibly
  • 原文地址:https://www.cnblogs.com/zhouhbing/p/3894444.html
Copyright © 2011-2022 走看看