C++ strptime 和strptime函数的使用方式
发布日期:2021-05-15 02:56:29 浏览次数:17 分类:精选文章

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

������������������������������������strptime���strftime���������������

������������������������������������������������������������������������C������������time.h������������������������������������������������������������������������������������������������������������������������������strftime���strptime���localtime���mktime���gmtime���������������������������������������������������������������

strptime���strftime������

strftime������������������������������tm���������������������������������������������������������������������������������������������������������������������������������������������strftime������������������

#include 
#include
#include
using namespace std;
int main() {
time_t rawtime;
struct tm *timeinfo;
char buffer[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
int length = strftime(buffer, 80, "%Y-%m-%dT%H:%M:%SZ\n", timeinfo);
printf("timestamp: %.*s", length, buffer);
return 0;
}

������������������strftime������������������"YYYY-MM-DDTHH:MM:SZ"���������������������������

���������strptime���������������������������������������������������������tm���������������strftime������������������������������������������������������������������������������"2001-11-12 18:31:01"���������������������

#include 
#include
#include
#include
using namespace std;
int main() {
struct tm *timeinfo;
char buffer[80];
memset(timeinfo, 0, sizeof(struct tm));
if (strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", timeinfo) != -1) {
int length = strftime(buffer, 80, "%Y-%m-%dT%H:%M:%SZ\n", timeinfo);
printf("timestamp: %.*s", length, buffer);
}
exit(EXIT_SUCCESS);
}

localtime���mktime������

localtime���������time_t���������������������������������tm������������mktime������������������tm���������������time_t���������������������������������������������������������������������������������mktime������������tm������������������������������������

������������������������������������������localtime���������������������

#include 
#include
using namespace std;
int main() {
time_t rawtime;
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
printf("���������������%TM\n", timeinfo);
return 0;
}

���������������������������������UTC���������������������������������������gmtime��������������������� UTC���������������tm���������

������

������������������������������������������������������������������������������������������������������������������������

  • ���������������������������������������time(0)���clock()������������������
  • ������strftime���strptime���������������������������������������������������
  • ���������������������������������tm���������������������������������
  • ������������������������������������������������������������������������������������������������������������������������

    上一篇:使用restbed 写入influxDB 数据库
    下一篇:我的系统居然和鸿蒙有点像

    发表评论

    最新留言

    逛到本站,mark一下
    [***.202.152.39]2025年04月30日 05时59分34秒