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.

Link to comment
Share on other sites

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.

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.