I am new in Deno. I want to know how can I convert Unix timestamp like 1646245390158
to 2000-01-01
or 2000-05-24 20:00:00
format or vice versa?
CodePudding user response:
Aside from the standard Javascript ways, there is a date/time library for Deno called Ptera, that can be used as follows:
import { datetime } from "https://deno.land/x/ptera/mod.ts";
const dt = datetime("2000-05-24 20:00:00");
console.log(dt.format("X")) // 959198400
const dt2 = datetime(1646245390158);
console.log(dt2.format("YYYY-MM-dd HH:mm:ss")) // output: 2022-03-02 19:23:10