string - 在 Impala 中将字符串转换为时间戳

标签 string casting timestamp impala

如何将表示日期时间的 string 转换为 "YYYY-MM-DD;HH:MM:SS" 格式(即 2016-04 -11;19:38:01) 到正确的时间戳

我认为这行得通,但行不通。

select 
  from_unixtime(unix_timestamp(`date`, "YYYY-MM-DD;HH:MM:SS"))
from t1
limit 100;

最佳答案

from_unixtime() 的返回类型不是“正确的timestamp”而是一个字符串。 (unix_timestamp() 的返回类型不是...timestamp,而是 bigint)。

这是我获取 timestamp 返回类型的方法:

select
  cast(unix_timestamp(`date`, "yyyy-MM-dd;HH:mm:ss") as timestamp)
from t1
limit 100;

为了完整起见,以下是我处理时区、本地格式化日期并将它们存储为 UTC 时间戳的方式:

select
  to_utc_timestamp(cast(unix_timestamp(`date`, "yyyy-MM-dd;HH:mm:ss") as timestamp), "Europe/Paris")
from t1
limit 100;

这假设 -use_local_tz_for_unix_timestamp_conversions 启动标志关闭(这是默认设置)。

关于string - 在 Impala 中将字符串转换为时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36724511/

相关文章:

mysql - 从 MySQL 中的时间戳获取日期名称

python - 如何在 Pandas 的持续时间计算中排除周末和节假日

c++ - 从字符串到字符串流再到 vector<int>

c# - 使用 ToString ("F1"时 float 的舍入不正确)

c# - 为什么我需要通过引用我的交换函数来传递字符串?

objective-c - 在 uint8_t * 和 char * 之间转换。会发生什么?

c - 遍历转换为 void* 的数组

java - android.support.v7.widget.AppCompatTextView 无法转换为 android.widget.RelativeLayout

java - 检查字符串是否需要调用 String.replaceAll() 与调用它

c - 我应该如何解释 gstreamer multifilesink 时间戳属性?