hive obtains the current system time

Get the current time of the system

  1. unix_timestamp()
    can use the unix_timestamp() function to obtain the current system time in hive, but this function obtains the bigint value.
    Insert picture description here
    As shown in the figure above, you can see that the current system time is obtained. The value type is bigint, but we usually want Get standard time, this time can be used with from_unixtime() function to get standard time.

  2. from_unixtime(bigint n,string str) The
    combination of from_unixtime() function and unix_timestamp() function is as follows The current time of the system, as shown in
    Insert picture description here
    the figure below. Through the figure above, we can see that we have obtained the current time of the standard system we need.

  3. unix_timestamp(string str) The
    above describes how to obtain the standard system time. When no parameters are filled in the parentheses of the unix_timestamp() function, the timestamp of the current system time is obtained. If the standard "yyyy-" is filled in the parentheses. The string of MM-dd HH:mm:ss" can get the timestamp of any specified standard time, as shown in the figure below.
    Insert picture description here
    If the string only has year, month and day, such as "2020-01-15", it can be obtained as follows Timestamp
    unix_timestamp("2020-01-15","yyyy-MM-dd"), the result is as shown in the figure below,
    Insert picture description here
    so that we can get the timestamp we want.

Guess you like

Origin blog.csdn.net/AnameJL/article/details/112256483