Jump to content

Require help formatting the time


JeremyCanada26

Recommended Posts

if I have a number like -5 which represents the offset from UTC, how do I format a time that I already have in this format? 2010-04-30 11:38:56"

 

btw, 2010-04-30 11:38:56 is already in UTC

 

I'd preferably like to break it up into two parts afterwards. One that says "April 10th, 2010" and another that says "6:38 PM"  (with no leading zero's)

Link to comment
Share on other sites

Wow that second line you used was very bloated Sergey, how about something like this

 

$hour_diff = -4;
$t = strtotime('2010-04-30 11:38:56');
$t = $t + ($hour_diff * 3600);
$t1 = date('F jS, Y',$t);
$t2 = date('h:i A',$t);

echo $t1 , $t2;

Link to comment
Share on other sites

Yours is in no way more accurate, mine adds the correct amount of seconds to the unix timestamp of the said time, and then formats it exactly like yours does. can you show me an example of how mine is different for any particular date?

Link to comment
Share on other sites

You're right JAY6390, I mistake. I have a delusion that adding hours, days etc. with just incrementing by NNN seconds might be incorrect, while function mktime() respect things like daylight saving time and leap years. Anyway I always use mktime rather than multiplying seconds.

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.