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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:10:09+00:00 2026-06-17T14:10:09+00:00

I have a javascript function to run time in different manner. Its working well

  • 0

I have a javascript function to run time in different manner.
Its working well in Chrome browser but its not showing proper value in Internet Explorer.

In Chrome:

13-Dec-2011 13:14:19

In IE8:

0NaN-undefined-NaN 0NaN:0NaN:0NaN

You can view this from this page link from both the browsers. Also look at the source code of page
http://chemfluence.org.in/monetarist/sample.php

My Code:

 <div id="txt" title="Industries will generate products on every 3 Virtual days. 
 12 Virtual Days = 1 Real day. dd-Mon-yyyy HH:MM:SS ."></div>

Javascript

<script type='text/javascript'>//<![CDATA[ 

var virtualOrigin = Date.parse("2012-02-27T00:00:00"),
    game_start_realdate=Date.parse("2013-01-27T12:00:00"),
    realOrigin = Date.now(),
    factor = 12;

function getVirtual(time) {
    return new Date( virtualOrigin + ((time - realOrigin) * factor)  +(realOrigin-game_start_realdate)*factor);
}

function pad2(num) {
    return ("0"+num).substr(-2);
}
function format(time) {
var month=new Array();
month[0]="Jan";
month[1]="Feb";
month[2]="Mar";
month[3]="Apr";
month[4]="May";
month[5]="Jun";
month[6]="Jul";
month[7]="Aug";
month[8]="Sep";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";
     return pad2(time.getDate())
        + "-" + month[time.getMonth()]
        + "-" + time.getFullYear()
        + " " + pad2(time.getHours())
        + ":" + pad2(time.getMinutes())
        + ":" + pad2(time.getSeconds());
}

function startTime() {
    var now = new Date();
    var display = getVirtual(now);
    output.innerText = format(display);
    setTimeout(startTime, 1000/factor - (now.getMilliseconds() % (1000/factor)));
}

var output = document.getElementById("txt");
startTime();

</script>

I need the above Javascript to be modified to work in Internet Explore and Chrome/Firefox;
Please give me modified code;

  • 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-17T14:10:11+00:00Added an answer on June 17, 2026 at 2:10 pm

    Try using moment.js. it is cross browser and can make doing dates in javascript much less of a pain. The documentation is very thorough. http://momentjs.com/docs/

    You can format your date with as little as:

    var day = moment("12-25-1995", "MM-DD-YYYY");

    http://momentjs.com/docs/#/parsing/string-format/

    UPDATE

    Here is an example of it’s full usage.

    var mysql_date = '2013-01-25 10:00:00'; // Date from MySQL database
    
    /**
     * @param     string     mysql_data     Date string
     * @param     string     format         Format in which mysql_data is set
     */
    var date = moment(mysql_date , 'YYYY-MM-DD HH:mm:ss'); // new moment.js object.
    
    // To display the date in a different format use:
    var date_format1 = date.format('MMM, Do'); // Format here would be Jan, 25th
    var date_format2 = date.format('MMMM, Do, YYYY'); // January, 25th, 2013
    
    console.log(date_format1, date_format2);
    

    You can change the format when ever you want. You don’t need to recreate it again.

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

Sidebar

Related Questions

I have a Javascript function that takes quite a long time to run. I
I have a JavaScript function that should only run on specific pages on a
Want to run javascript function from parent window in child window Example I have
I have several javascript files that during run-time get combined and minified. This is
I have some function I want to time, but I have no idea how
I have a JavaScript function that I need to run. It takes some parameters.
I have Javascript function defined in the main index.html file. One part of this
in .gsp file i have javaScript function <script type=text/javascript> function getCurrentItemNumber(){ return document.getElementById('item_itemNumber').innerHTML.substr(6); }
I have a javascript function from which I need to call a controller action
I have this Javascript function that sends username and password to php file through

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.