hive 的 unix_timestamp 和 to_unix_timestamp
时间: 2023-09-07 19:14:57 浏览: 75
Hive中的`unix_timestamp`函数将一个字符串类型的时间转换为UNIX时间戳,即从1970年1月1日零时零分零秒开始到该时间的秒数。该函数的语法如下:
```
unix_timestamp(string date)
unix_timestamp(string date, string pattern)
```
第一个参数`date`为需要转换的时间字符串,第二个参数`pattern`为时间字符串的格式,如果不指定则默认为`yyyy-MM-dd HH:mm:ss`。
而`to_unix_timestamp`函数是将一个时间类型的数据转换为UNIX时间戳,其语法如下:
```
to_unix_timestamp(timestamp|date|string)
```
该函数的参数可以是一个时间类型的数据,也可以是一个字符串类型的时间,函数会自动识别并转换为UNIX时间戳。
需要注意的是,`unix_timestamp`函数返回的是一个整型数值,而`to_unix_timestamp`函数返回的是一个DOUBLE类型的数值。
相关问题
hive unix_timestamp
The UNIX_TIMESTAMP function in Hive returns the number of seconds since January 1, 1970, 00:00:00 UTC, also known as the UNIX epoch.
Syntax:
UNIX_TIMESTAMP()
UNIX_TIMESTAMP(string date)
UNIX_TIMESTAMP(string date, string pattern)
Example:
1. SELECT UNIX_TIMESTAMP();
Output: 1619021362
2. SELECT UNIX_TIMESTAMP('2021-04-21');
Output: 1618982400
3. SELECT UNIX_TIMESTAMP('2021-04-21 12:30:15', 'yyyy-MM-dd HH:mm:ss');
Output: 1619019015
hive unix_timestamp函数
hive中的unix_timestamp函数是将指定日期时间转换为对应的Unix时间戳,即从197年1月1日00:00:00到指定时间的秒数。该函数的语法如下:
unix_timestamp([string date [, string pattern]])
其中,date是要转换的日期时间字符串,pattern是date的格式,如果不指定则默认为yyyy-MM-dd HH:mm:ss。如果date和pattern都不指定,则返回当前时间的Unix时间戳。该函数返回一个long类型的整数值。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)