Solved

Date Hours Minutes and AM/PM in javascript function

Posted on 2006-11-16
1
1,119 Views
Last Modified: 2012-06-27
In my javascript function I am getting date value as show below

var sDate=Cal.FormatDate(PValue);
var sHours=winMain.Cal.getShowHour();
var sMinutes=winMain.Cal.Minutes;
var sAMPM=winMain.Cal.AMorPM;

when we consolidate all the above the final date will look like eg: 11/16/2006 03:15 PM

Now I want to add 30 Minutes to the minutes which should take all the following scenarios: like if I add 30 minutes to
11/16/2006 11:45 PM
it should show  11/17/2006 00:15 AM

and so on

Please help
0
Comment
Question by:rowmark
1 Comment
 
LVL 2

Accepted Solution

by:
Messiadbunny earned 500 total points
ID: 17962877
<script type="text/javascript">

curdate = new Date()

dateVar = new Date(curdate.getFullYear(), curdate.getMonth(), curdate.getDate(),curdate.getHours(),curdate.getMinutes() + 30,curdate.getSeconds())
//This collects all the data from the current date, except adds 30 mins as shown above
// curdate.getMinutes() + 30 is the specific line that adds 30 mins.

if (dateVar.getHours() < 12 & dateVar.getHours() > 0)
{
//If time is less than noon, but before 1 AM
curhour = dateVar.getHours()
ampm = "A.M."
}
else if (dateVar.getHours() == 12)
{
//If it's exactly 12 PM (Noon ish)
curhour = 12
ampm = "P.M."
}
else if (dateVar.getHours() == 0)
{
//1 AM in the morning
curhour = 1
ampm = "A.M."
}
else
{
//If it's any other time, 1 PM - 12 PM
curhour = dateVar.getHours() - 12
ampm = "P.M."
}

mdhour = curhour
mdminute = dateVar.getMinutes()
mdyear = dateVar.getFullYear()
mdmonth = dateVar.getMonth()
mdday = dateVar.getDate()

//re-collect all the variables incase the day/month/year/ have changed with the addition of //30 mins.

document.write(mdmonth + "/" + mdday + "/" + mdyear + " " + mdhour + ":" + mdminute + " " + ampm)




</script>
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now