Linux下字符串转时间tm结构函数strptime
来源:互联网 发布:淘宝涮单可靠吗 编辑:程序博客网 时间:2024/06/15 18:05
原型:
char *strptime(const char *buf,const char *format,struct tm *timeptr)
buf: tm格式化后的C字符串(以0结尾);
format: 字符串格式,构建方式与strftime的format字符串完全一样;
struct tm *timeptr:转换后存储tm值的指针;
返回值: 指向转换过程处理的最后一个字符后面的那个字符。
功能:
将一个字符串格式化为一个tm结构,功能与strptime相反。
format参数:
转换控制符 说明
%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 当地格式的日期
%X 当地格式的时间
%y 年份中的最后两位数,00-99
%Y 年
%Z 地理时区名称
测试程序
运行结果:
char *strptime(const char *buf,const char *format,struct tm *timeptr)
buf: tm格式化后的C字符串(以0结尾);
format: 字符串格式,构建方式与strftime的format字符串完全一样;
struct tm *timeptr:转换后存储tm值的指针;
返回值: 指向转换过程处理的最后一个字符后面的那个字符。
功能:
将一个字符串格式化为一个tm结构,功能与strptime相反。
format参数:
转换控制符 说明
%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 当地格式的日期
%X 当地格式的时间
%y 年份中的最后两位数,00-99
%Y 年
%Z 地理时区名称
测试程序
源码:
#include "time.h"#include "stdio.h"int main(void){time_t lt = time(NULL);struct tm* ptr = localtime(<);char szBuffer[64] = {0};const char* pFormat = "The time now is %Y-%m-%d %H:%M:%S";strftime(szBuffer, 64, pFormat, ptr);printf("%s\n", szBuffer);struct tm tmTemp;char tmBuffer[64] = {0};strptime(szBuffer, pFormat, &tmTemp);strftime(tmBuffer, 64, "The time just was %Y-%m-%d %H:%M:%S", &tmTemp);printf("%s\n", tmBuffer);return 0;}
运行结果:
- Linux下字符串转时间tm结构函数strptime
- Linux下字符串转时间tm结构函数strptime
- Linux下字符串转时间tm结构函数strptime
- linux时间函数描述-strptime
- linux 时间格式化函数strftime和strptime使用
- linux 时间格式化函数strftime和strptime使用
- 3.13 调用strptime函数前需初始化tm
- Linux C时间函数 time_t struct tm
- Linux下的时间结构及函数
- linux下与时间相关的结构体 struct timeb,struct timeval ,struct timezone,struct timespec,struct tm 等
- linux下时间的转换 timeval /time_t time_t/tm
- linux下时间的转换 timeval /time_t time_t/tm
- Linux下的时间--struct tm, mktime, localtime, strftime
- Linux下的时间相关结构和函数
- linux下时间有关的函数和结构体
- linux下时间有关的函数和结构体
- linux下时间有关的函数和结构体
- linux下时间有关的函数和结构体
- 一些开源项目网址
- EJB3.0笔记-实体查询与EJB QL
- netezza 的代替函数
- Mina Server实例
- VisualVM 入门指南
- Linux下字符串转时间tm结构函数strptime
- delphi处理文档类问题
- vector的成员函数 和简单的使用代码
- 用sql语句汇总 实现语句的合并
- OpenVPN上传流量高,占用大量CPU问题分析
- How to add CTS test cases
- 判别模型 和 生成模型
- 让viewDidAppear/viewWillAppear 在页面加载前始终调用
- ext2文件系统总体存储布局