如何在没有 FROM_UNIXTIME() 函数的情况下将 unix 时间转换为 GMT+8 人类可读日期?

How to convert a unix time to GMT+8 human readable date without FROM_UNIXTIME() function?

由于 mysql Generated Column 无法使用 FROM_UNIXTIME() 作为生成 sql,我如何将 unix 时间转换为 GMT+8 人类可读日期?我失败的例子:

    ALTER TABLE just_a_table
    ADD COLUMN created_date
    CHAR(5) 
    GENERATED ALWAYS 
        AS (FROM_UNIXTIME(created_at, "%m/%d")) 
        STORED;

Since mysql Generated Column can't use FROM_UNIXTIME() as generate sql

???

FROM_UNIXTIME() 是确定性函数。它可以很容易地用于生成的列表达式。

CREATE TABLE just_a_table (created_at BIGINT);
INSERT INTO just_a_table VALUES 
(UNIX_TIMESTAMP(NOW() - INTERVAL 1 HOUR)),
(UNIX_TIMESTAMP(NOW() - INTERVAL 2 DAY));
ALTER TABLE just_a_table
ADD COLUMN created_date CHAR(5) 
    GENERATED ALWAYS AS (FROM_UNIXTIME(created_at, "%m/%d")) STORED;
SELECT * FROM just_a_table
created_at | created_date
---------: | :-----------
1619167553 | 04/23       
1618998353 | 04/21       

db<>fiddle here