Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8461839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:59:22+00:00 2026-06-10T13:59:22+00:00

Determining a user’s timezone server side and converting from UTC has proven more trouble

  • 0

Determining a user’s timezone server side and converting from UTC has proven more trouble than its worth.

Is there a reliable way for javascript/jquery to determine the timezone of the user and apply the offset to a UTC datetime stamp (2012-08-25 10:59:56.511479) and output in my desired format (Aug 25 ’12 – 10:59AM)?

What might the jquery code look like to say

// dom ready
$('span.localtime').each(function(e) {
    // get stamp and apply conversion
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:59:24+00:00Added an answer on June 10, 2026 at 1:59 pm

    .getTimezoneOffset() is available on the date object, and gives you the offset from UTC in minutes.

    var offset = (new Date()).getTimezoneOffset();
    
    // convert myUtcDate to a date in local time
    myUtcDate.setMinutes(myUtcDate.getMinutes() + (offset*-1));
    

    Thus:

    $('.span.localtime').each(function() {
       var myUtcDate = new Date($(this).html()); // assuming "2012-08-25 10:59:56.511479"
       myUtcDate.setMinutes(myUtcDate.getMinutes() + (myUtcDate.getTimezoneOffset() * -1));
    
       $(this).html(myUtcDate.toString());
    });
    

    Note that myUtcDate.toString() could be replaced with any date formatting you want. In your case, it might look like

    $(this).html(formatDate(myUtcDate));
    
    function formatDate(d) {
    
       var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    
        var y = d.getFullYear().toString().slice(-2); // "12"
        var m = months[d.getMonth()]; // "Aug"
        var d = d.getDate(); // "25"
    
        var ampm = 'AM';
        var h = d.getHours();
    
        if(h>=12) {
            h -= 12;
            ampm = 'PM';
        }
    
        if(h == 0)
           h = 12;
    
        var min = ("00" + d.getMinutes()).slice(-2);
    
        return m + " " + d + " '" + y + " - " + h + ":" + min + ampm;
    }
    

    You might want to use a date format plugin for formatting dates in a neater more reliable manner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble determining if it's possible, based on the amount of access I
Is there a generic way of determining all attributes (and their values) from an
Given my recent (somewhat successful) question: Algorithmic issue: determining "user sessions" I'm pretty sure
I have a LinkButton within a User Control and it has handled with: Private
This function is called from the form_onload. I am basically reading the registry, determining
I always have the the trouble in determining whether I should put business logic
I'm determining a user's language preference through some third party service he's also registered
Is there a way of determining the user login used for the Application Pool
What is the code for determining if a user is in a role? I
What's the best way for determining whether the user's browser can view PDF files?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.