如何转换“2012-03-02”进入unix时代的C? [英] How do I convert "2012-03-02" into unix epoch time in C?

查看:138
本文介绍了如何转换“2012-03-02”进入unix时代的C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2012年3月2日的字符串2012-03-02作为输入变量(char *)给予了我。

A string "2012-03-02" representing March 2nd, 2012 is given to me as an input variable (char *).

如何以C编程语言将此日期转换为unix时代?

How do I convert this date into unix epoch time in C programming language?

推荐答案

C(POSIX)为此提供了一个功能。使用 strptime() 将字符串转换为 struct tm 值。然后,您可以使用 struct tm 转换为 time_t /onlinepubs/007904875/functions/mktime.htmlrel =nofollow> mktime()

C (POSIX) provides a function for this. Use strptime() to convert the string into a struct tm value. You can then convert the struct tm into time_t using mktime().

这篇关于如何转换“2012-03-02”进入unix时代的C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆