Start a conversation

Converting UTC Time to Local Time in Hovered Replies

Overview

When hovering over an answer or reply, the time is displayed in UTC instead of the local timezone. This issue can be resolved by adding a script to the custom header/footer configuration, which converts the displayed time to the user's local timezone.

Information

Issue: Time displayed in UTC instead of local timezone when hovering over answers or replies.

Resolution Steps:

  1. Access Custom Configurations:
    • Navigate to the admin area of your instance.
    • Go to Site > Custom Configurations > Custom Header/Footer.
  2. Add the Script:

    In the "Head Content" section, add the following script:

    <script>
    document.addEventListener("DOMContentLoaded",(function(){var e=document.querySelectorAll("span.action-date"),t={month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0};e.forEach((function(e){var n=e.querySelector("time[datetime]");if(n){var r=n.getAttribute("datetime"),i=new Date(r);if(!isNaN(i.getTime())){var o=i.toLocaleString("en-US",t);e.setAttribute("title",o),n.textContent=o}}}))}));
    </script>
                
  3. Save Changes:
    • Save the changes to the custom header/footer configuration.
  4. Reload the Page:
    • Reload the page to apply the changes and verify that the time is now displayed in the local timezone.

Verification:

  • Hover over an answer or reply to confirm that the time is displayed in the local timezone instead of UTC.

Frequently Asked Questions

How do I know if this issue applies to my instance?
If the time displayed when hovering over answers or replies is in UTC instead of your local timezone, this issue applies to your instance.
What should I do if the time is still displayed in UTC after adding the script?
Ensure that the script is correctly added to the "Head Content" section and that the page has been reloaded. If the issue persists, contact support for further assistance.
Can I customize the time format displayed?
Yes, you can modify the script to change the time format by adjusting the options in the toLocaleString method.
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Priyanka Bhotika

  2. Posted

Comments