diff --git a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_AdminLayout.cshtml b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_AdminLayout.cshtml index ff9c8a9ac8b..bfe03dd620e 100644 --- a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_AdminLayout.cshtml +++ b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_AdminLayout.cshtml @@ -200,8 +200,12 @@ {
} +
- @((await dateTimeHelper.ConvertToUserTimeAsync(DateTime.Now)).ToString("f", CultureInfo.CurrentCulture)) + + @((await dateTimeHelper.ConvertToUserTimeAsync(DateTime.UtcNow)).ToString("f", CultureInfo.CurrentCulture)) +
nopCommerce version @NopVersion.FULL_VERSION @@ -311,6 +315,9 @@ } + + + @NopHtml.GenerateScripts(ResourceLocation.Footer) @NopHtml.GenerateInlineScripts(ResourceLocation.Footer) diff --git a/src/Presentation/Nop.Web/wwwroot/js/admin-footer-time.js b/src/Presentation/Nop.Web/wwwroot/js/admin-footer-time.js new file mode 100644 index 00000000000..ef0e951e073 --- /dev/null +++ b/src/Presentation/Nop.Web/wwwroot/js/admin-footer-time.js @@ -0,0 +1,46 @@ +(function () { + var el = document.getElementById('admin-now'); + if (!el) return; + + var utc = el.getAttribute('data-utc'); + if (!utc) return; + + // Initial UTC value from the server + var startUtc = new Date(utc).getTime(); + // When the script started (client timestamp) + var mountedAt = Date.now(); + + // Format similar to .NET "f" (Long date + short time, without seconds) + function formatLikeF(d) { + try { + return d.toLocaleString(undefined, { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: '2-digit', + minute: '2-digit' + }); + } catch { + return d.toLocaleString(); + } + } + + function render() { + // How much time has passed on the client since mount + var elapsed = Date.now() - mountedAt; + // "Now" = server UTC + elapsed time, displayed in the admin's local zone + var nowLocal = new Date(startUtc + elapsed); + el.textContent = formatLikeF(nowLocal); + } + + // First update immediately + render(); + + // Update every minute (enough since we don’t show seconds) + var timer = setInterval(render, 60 * 1000); + + // Cleanup (best practice) + window.addEventListener('unload', function () { + clearInterval(timer); + }); +})();