Jump to content

[SOLVED] Question about date time


temujinleal

Recommended Posts

Good day experts!! I would like to ask if is it possible in a date() function to determine that it will only change to PM or AM if it is already 1 o clock?

 

for example:

 

if the time now is 12AM, the next hour will be 1PM then after 12hours, it will be 1AM but before 1AM, it is still 12PM...

I'm just concern about the transition from AM to PM...

 

Thanks!! cheers!!

Link to comment
Share on other sites

date() requires a timestamp of some form... whether given directly or created with mktime(). No timestamp supplied implies the current time timestamp. The timestamp always knows whether AM or PM in 12 hour formatted displays, so if you include the AM/PM indicator, it will always be accurate.

 

PhREEEk

Link to comment
Share on other sites

the switch from AM to PM or PM to AM is made instantly, not after an hour has elapsed

 

If you run this script, which increments the time by 1 second

 

<?php

echo "<h3>At Midday</h3>";
$start = mktime (11,59,55);

for ($i=0; $i<10; $i++) echo date ('g:i:s A', strtotime("+$i seconds", $start)), '<br>';

echo "<h3>At Midnight</h3>";
$start = mktime (23,59,55);

for ($i=0; $i<10; $i++) echo date ('g:i:s A', strtotime("+$i seconds", $start)), '<br>';

?>

 

you get

[pre]At Midday

11:59:55 AM

11:59:56 AM

11:59:57 AM

11:59:58 AM

11:59:59 AM

12:00:00 PM

12:00:01 PM

12:00:02 PM

12:00:03 PM

12:00:04 PM

 

At Midnight

11:59:55 PM

11:59:56 PM

11:59:57 PM

11:59:58 PM

11:59:59 PM

12:00:00 AM

12:00:01 AM

12:00:02 AM

12:00:03 AM

12:00:04 AM

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.