Help with defining a Timestamp format

Discussion in 'JavaScript' started by webwizzy, Dec 23, 2012.

  1. #1
    Hi there,

    I have a function here that outputs the current timestamp in local timezone.

    function EpochToHuman2(){
    var currentTime = new Date()
    var currentmillitime = currentTime.getTime()
        var inputtext = currentmillitime;
        var epoch=inputtext;
        var outputtext = "";
        var extraInfo = 0;
        if(inputtext > 1000000000000){
            epoch=Math.round(inputtext/1000);
        }else{
            if(inputtext > 10000000000)extraInfo=1;
            inputtext=(inputtext*1000);
        }
        var datum = new Date(inputtext);
        var localeString = datum.toLocaleString();
        var localeStringEnd = localeString.search(/GMT/i);
        if(localeStringEnd>0){ localeString=localeString.substring(0,localeStringEnd); }
        outputtext += localeString;    
        document.write(outputtext);
    }
    
    Code (markup):
    Now, the output it generates in Chrome is Sun Dec 23 2012 17:14:49 and in Firefox it shows as 23 December 2012 17:14:49. (Notice the different formats for both browsers).
    I need to show it like the first format for all browsers. I guess I need to define the format in this case in the function itself but not sure how.

    Would appreciate some help here! Thanks.
     
    Last edited: Dec 23, 2012
    webwizzy, Dec 23, 2012 IP
  2. webwizzy

    webwizzy Active Member

    Messages:
    511
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    85
    #2
    Okay, so after investing quite some time on this, I was able to figure it out. The below changes to the function should take care of everything.

    
    function EpochToHuman2(){
    var currentTime = new Date()
    var currentmillitime = currentTime.getTime()
    
    Code (markup):
     
    webwizzy, Dec 23, 2012 IP