Question : Javascript - output date and time

Hi,
Being new at javascript I need some guidance. I'm installing a script on my website that I need to configure.

How do I output Tomorrows date at 12pm in the following format -
"24/06/2010 @ 12:00 PM" (dd/mm/yyyy @ hh:mm PM)

I need to make it dynamic based on the current date

On top of that....
IF current time is 2pm or later, output the date two days from now.

Regards
Mitch

Answer : Javascript - output date and time

I have written as per your needs. If you want to set the time as always 12:00 PM, you can just add it as hard code string. In following code, I have displayed current time instead of hard code ' 12:00 PM'. By default JavaScript will return in 24 Hrs format and I manipulated to display in 12 Hrs format. Following is my sample code:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
<script language="javascript" type="text/javascript">
        var objDate = new Date();
        var objNewDate = new Date();
        var strTwelveHourFormat = objDate.getHours();
        var strMinutes = objDate.getMinutes();
        var strAM_PM = ' AM';

        if(strTwelveHourFormat>=12)
        {
            strTwelveHourFormat = strTwelveHourFormat - 12;
            strAM_PM = ' PM';
        }
        if(strTwelveHourFormat<10)
        {
            strTwelveHourFormat = '0' + strTwelveHourFormat;
        }
        if(strMinutes<10)
        {
            strMinutes = '0' + strMinutes;
        }
        //alert(objDate);
        if(objDate.getHours() >= 14)
        {
            objDate.setDate(objDate.getDate()+2);//Day after tomorrow.
        }
        else
        {
            objDate.setDate(objDate.getDate()+1);//Tomorrow.
        }
        objDate.setHours(24, 0, 0, 0);
        alert(objDate.getDay() + '/' + (objDate.getMonth() + 1) + '/' + objDate.getFullYear() + ' @ ' + strTwelveHourFormat + ':' + strMinutes + strAM_PM);
        
    </script>
Random Solutions  
 
programming4us programming4us