mirror of
https://github.com/zadam/trilium.git
synced 2025-10-30 18:05:55 +01:00
moved date functions to utils.js
This commit is contained in:
@@ -47,4 +47,26 @@ function uint8ToBase64(u8Arr) {
|
||||
|
||||
function base64ToUint8Array(base64encoded) {
|
||||
return new Uint8Array(atob(base64encoded).split("").map(function(c) { return c.charCodeAt(0); }));
|
||||
}
|
||||
|
||||
function getDateFromTS(timestamp) {
|
||||
// Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling
|
||||
// see https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript
|
||||
const utcDate = new Date(timestamp * 1000);
|
||||
|
||||
const localDate = new Date(utcDate.getTime() - utcDate.getTimezoneOffset() * 60 * 1000);
|
||||
|
||||
return localDate;
|
||||
}
|
||||
|
||||
function formatTime(date) {
|
||||
return (date.getHours() <= 9 ? "0" : "") + date.getHours() + ":" + (date.getMinutes() <= 9 ? "0" : "") + date.getMinutes();
|
||||
}
|
||||
|
||||
function formatDate(date) {
|
||||
return date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear();
|
||||
}
|
||||
|
||||
function formatDateTime(date) {
|
||||
return formatDate(date) + " " + formatTime(date);
|
||||
}
|
||||
Reference in New Issue
Block a user