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 8791471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:50:51+00:00 2026-06-13T22:50:51+00:00

I have used a Javascript function for converting date to UTC date as follows:

  • 0

I have used a Javascript function for converting date to UTC date as follows:

Date.prototype.convertToUTC = function () {
var month = this.getMonth();
var day = this.getDate();
var year = this.getFullYear();
return new Date(Date.UTC(year, month, day));
}

Now the problem arises when the date on which this function is applied is already in UTC. Since I don’t know whether user will call this method on UTC/Local date, I want to ensure conversion happens only if it is not in UTC. Please help.

  • 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-13T22:50:51+00:00Added an answer on June 13, 2026 at 10:50 pm

    All dates have a UTC time value at their heart. Date objects created in a host are given a read–only timezone offset based on the system settings, and values read using getDate, getHours, etc. are based on that offset.

    If you want UTC milliseconds since the epoch, just use the getTime() method. Alternatively, there are the UTC methods, getUTCDay, getUTCHours, etc. to build your own formatted string.

    Finally, there is toISOString which should return an ISO formatted date string for UTC, but support may be lacking in not so old browsers.

    Some examples

    To create a local date object for 2012-11-06T15:45:01Z:

    var date = new Date(Date.UTC(2012, 10, 6, 15, 45, 1));
    

    To get an ISO date string from that (or any) date object:

    var isoString = date.toISOString();
    

    To get a UTC time value in milliseconds (ms since 1970-01-01T00:00:00Z):

    var timeValue = date.getTime();
    

    To turn that time value back into a local date object:

    var date = new Date(timeValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used Javascript onlaod like this: function check() { var pic = new
I have a problem when call applet method from javascript.. I used this function
I have used this javascript function: $(document).ready(function(){ $(td).each(function() { if (parseInt($(this).text()) > 0) {
I have used JavaScript on body onload event I used this code: function timeMsg()
I have one javascript function that used to display the menu and content in
I have a javascript function I'm writing which is being used to include an
I have a JavaScript function which have been used to post something to the
i have a javascript function that creates inputfields for uploading images. i have this
I have a function in java script, that I used it to take the
I have used a javascript to show div by onclick but when i click

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.