Jump to content

PHP mktime() to format: "Tuesday, January 2, 2011 at 12:05pm"


shortysbest

Recommended Posts

I want to have a couple of different formats from mktime(), which the value could be: 1292183335.

 

I would like to have some of the formats like:

 

Tuesday at 12:00am,

Wednesday, January 12, 2011 at 12:00am

 

Also taking different timezones in consideration. I'm not sure what to use for that.

date('l jS \of F Y h:i:s A T', mktime());

 

That will format the current mktime into the format you wanted (with the addition of the abbreviated timezone, you can take that out by removing T from the first argument.)  If you want to convert a timestamp already in a variable to the same format, just replace the mktime() portion to your timestamp variable (or just enter the timestamp.)

 

I *think* that if you haven't set a default timezone for php, it defaults to the server timezone, from there I would think you can just add or minus hours based on the timezone you want.  I have a utility function I include in scripts that I send a timestamp to and it sends back an array with all the different timezones in it, so if I wanted a timezone in EST, I send it something like:

 

$this->timeConv = $this->utils->convTime($timestamp)
echo $this->timeConv['EST'];

 

You can also have that array contain values for the day, month, year, etc individually and then formatted in different ways and a few ways that is formatted altogether (I have one that is fullDate and then fullDateTime and fullTime, etc) - anyway, just a thought.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.