Get the current time of the system
-
unix_timestamp()
can use the unix_timestamp() function to obtain the current system time in hive, but this function obtains the bigint value.
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. -
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
the figure below. Through the figure above, we can see that we have obtained the current time of the standard system we need. -
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.
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,
so that we can get the timestamp we want.