Display date with browser timezone

This commit is contained in:
Thomas 2025-04-03 16:06:15 +02:00
parent 618da03e0e
commit 4ffe74a73a
2 changed files with 9 additions and 6 deletions

View file

@ -396,6 +396,7 @@
<script src="{{ asset('js/moment.js') }}"></script>
<script src="{{ asset('js/emojionearea.js') }}"></script>
<script type="text/javascript">
$(function() {
'use strict';
@ -545,14 +546,16 @@
searchPosition: "bottom",
search: false
});
var timezone;
let userTimezone;
if(!!sessionStorage.getItem('timeZone')) {
timezone = sessionStorage.getItem('timeZone');
userTimezone = sessionStorage.getItem('timeZone');
} else {
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
}
$('#compose_timeZone').val(timezone);
$("#compose_scheduled_at").val(new Date(new Date().toString().split('GMT')[0]+' UTC').toISOString().split('.')[0]);
$('#compose_timeZone').val(userTimezone);
$('#compose_timeZone').on('change', function () {
sessionStorage.setItem("timeZone", this.value);
});

View file

@ -58,7 +58,7 @@
lang = navigator.language.slice(0,2);
}
function convertTZ(date) {
return new Intl.DateTimeFormat(lang, { dateStyle: "full" , timeStyle: "long", timeZone: userTimezone}).format(new Date(date)).toLocaleString();
return new Intl.DateTimeFormat(lang, { dateStyle: "full" , timeStyle: "long", timeZone: userTimezone}).format(new Date(date + " UTC")).toLocaleString();
}
$(document).ready(function() {