将string类型的time转为Unixtime
时间: 2023-03-25 12:01:06 浏览: 65
可以使用time.h头文件中的函数来将string类型的time转为Unixtime,具体的代码如下:
```c
#include <stdio.h>
#include <time.h>
int main() {
char str_time[] = "2022-01-01 00:00:00";
struct tm tm_time;
time_t unix_time;
strptime(str_time, "%Y-%m-%d %H:%M:%S", &tm_time);
unix_time = mktime(&tm_time);
printf("Unixtime: %ld\n", unix_time);
return ;
}
```
其中,strptime函数可以将string类型的time转为tm结构体类型的时间,mktime函数可以将tm结构体类型的时间转为Unixtime。
相关问题
go 将int64转为time
可以使用time.Unix()函数将int64转换为time类型。例如:
```go
timestamp := int64(1609459200) // 这是2021年1月1日的时间戳
t := time.Unix(timestamp, 0)
fmt.Println(t) // 输出: 2021-01-01 00:00:00 +0000 UTC
```
其中,`timestamp`为需要转换的int64类型的时间戳,`0`表示时区偏移量,如果不需要时区偏移量,可以设置为0。最后使用`time.Unix()`函数将int64类型的时间戳转换为time类型。
hive FROM_UNIXTIME
Hive provides the `FROM_UNIXTIME` function to convert a UNIX timestamp (in seconds) to a string representing the corresponding date and time. The syntax for using `FROM_UNIXTIME` in Hive is as follows:
```
SELECT FROM_UNIXTIME(unix_timestamp) AS formatted_date
FROM your_table;
```
Here, `unix_timestamp` is the column or expression representing the UNIX timestamp you want to convert. `formatted_date` is an optional alias for the resulting formatted date string.
For example, if you have a table named `your_table` with a column `timestamp_col` containing UNIX timestamps, you can use the following query to convert them to formatted dates:
```
SELECT FROM_UNIXTIME(timestamp_col) AS formatted_date
FROM your_table;
```
This will return a result set with the formatted dates corresponding to the UNIX timestamps.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)