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

  • SEARCH
  • Home
  • 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 6319463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:48:38+00:00 2026-05-24T15:48:38+00:00

I have the following text on my page: <span class=UTCDate>Date.UTC(2011, 8, 7, 7, 9,

  • 0

I have the following text on my page:

<span class="UTCDate">Date.UTC(2011, 8, 7, 7, 9, 20)</span>

I’d like to do something like this:

 $(function () {

     $('.UTCDate').each(function () {
         var server_time_utc = $(this).html();
         var subbed = new Date(server_time_utc - 12 * 60 * 60 * 1000);
         var d = new Date(subbed + new Date().getTimezoneOffset());
         var localTime = $.format.date(d, "ddd, MMMM dd GG hh:mma");
         localTime = localTime.replace("GG", "at");
         $(this).html(localTime);
     });

 });

I’m taking the UTC Date, changing it to the local browsers time and formatting it.

My problem is I get a string instead of a date object in this line:

 var server_time_utc = $(this).html();

If I type:

var server_time_utc = Date.UTC(2011, 8, 7, 7, 9, 20);

I get a date object.

How can I make the text from $(this).html() return a date object instead of a string?

EDIT
The string I get is
server_time_utc: “Date.UTC(2011, 8, 7, 7, 9, 20)”

  • 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-05-24T15:48:39+00:00Added an answer on May 24, 2026 at 3:48 pm

    Accept a wider range of inputs

    var matches = $(this).html().match(/\d+/g);
    var date = new Date(Date.UTC.apply(this, matches));
    

    This function will pull each number out of that string in order, then call Date.UTC with each number and return your Date object.

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

Sidebar

Related Questions

Lets say i have the following web page: <html> <body> <div class="transform"> <span>1</span> </div>
I have the following XPath to match authors name in an Amazon page: //div[@class='pTitle']/span[@class='small
I have a raw text with the following format: page 1 -page 1.1 --page
I have the following text tooooooooooooon According to this book I'm reading, when the
I have the following text: We%27re%20proud%20to%20introduce%20the%20Amazing I'd like to remove the encoding using PHP,
I have the following code snippet I'm trying to get the text from: <span
I have a problem with the following code in an ASPX page: <script type=text/javascript>
Given the following HTML on a page: <div class='test'> <p><span id='id1' class='test1 test2 test3'>test
I have the following in my application layout page <body> <div class=container showgrid> <%=
I have the following form declaration: <div class=edit-dialog span-10 style=display:none;> <div class=edit-message span-10 style=margin-bottom:30px;>

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.