1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Little help with stripping off/re-arranging text

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

  1. #1
    Hi there,

    I have this in a variable:

    Mon Dec 24 05:59:51 UTC+0530 2012
    Code (markup):
    I need to show it like this instead:

    Mon Dec 24 2012 05:59:51
    Code (markup):
    So basically I just need to strip off the "UTC" part and move "2012" before the time.
    I'm able to strip the UTC part off by doing a search, but not sure how to move "2012" before the time. Or maybe some smarter way to do this in one line of code, regexp maybe?

    Thanks for your help.
     
    webwizzy, Dec 24, 2012 IP
  2. architgupta

    architgupta Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you are getting it from time stamp why not to use date time formats that are already available in the js.
     
    architgupta, Dec 26, 2012 IP
  3. webwizzy

    webwizzy Active Member

    Messages:
    511
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    85
    #3
    I should have explained the whole story! :)

    I'm indeed using the date/time formats through JS. However, I need the format to be consistent across browsers. The display is standard across all browsers, except IE (tested on IE9 on Win7 and IE10 on Win8). For some reason, IE doesn't respect such a basic standard that every single browser does (even Chrome and Safari for iOS does). Hence, I'll apply a conditional that does a browser check if its IE and strip the UTC part off and move 2012 before the time.

    Stripping part is okay, and using indexOf method I'm able to find out the location where I need the "year" to display. Just need to figure out how to insert it now.

    Thanks.
     
    webwizzy, Dec 27, 2012 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    What date object method are you using to generate that date? The deprecated toGMTString(), or the proper toUTCString() one? Also are you sure you're in a modern doctype and not in quirks mode? IE's jscript doesn't behave the same in quirks or certain doctypes.

    Part of why putting up a full working example is important when you ask a question -- as there are often more questions that need to be answered first.
     
    deathshadow, Dec 27, 2012 IP