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.

change the format of date object

Discussion in 'JavaScript' started by mystic-d, Sep 22, 2007.

  1. #1
    hey
    i need to change the format of inserting the date value into the date object, someone know how can i do this ?
    i need to enter this format :

    DD/MM/YYYYY hh:mm (beside : MM/DD/YYYY hh:mm)
    i was try this :
    date=new Date("30/10/2007 11:11");
    but its not working...
    thanks !
     
    mystic-d, Sep 22, 2007 IP
  2. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try using this:
    var date = new Date();
    var formattedDate = "";
    formattedDate = (date.getDate() < 10 )? "0" + date.getDate() : date.getDate();
    formattedDate += "/";
    formattedDate += (date.getMonth() < 10)? "0" + (date.getMonth()+1) : date.getMonth()+1;
    formattedDate += "/";
    if ( date.getYear() <= 99) {
      formatedDate += "19"+date.getYear();
    }
    if ( date.getYear() > 99 && date.getYear() < 2000 ){
      formattedDate += new String(date.getYear() + 1900);
    }
    formattedDate += " " + (date.getHour() < 10)? "0" + date.getHour() : date.getHour();
    formattedDate += ":" + (date.getMinutes() < 10)? "0" + date.getMinutes() : date.getMinutes();
    Code (markup):
    I haven't tested it, so there will probably be some errors :)
     
    UnrealEd, Sep 22, 2007 IP