0

In php I have time like this

$time = '2015-06-29T16:00:00Z';

I want to convert that time like this format Tuesday, December 16, 2015 3:00 PM

For that I tried echo date( 'jS F Y', strtotime( $time) );

but it is showing time like 1st January 1970 So can someone help me to get the actual time format as I want.

2
  • 1
    There are multiple date times. Commented May 21, 2015 at 4:15
  • Check the update in the answer, you will get that format. Commented May 21, 2015 at 4:22

5 Answers 5

3

A simple DateTime class usage should suffice, just feed it into the constructor, the just use ->format and provide the desired output format:

$time = '2015-06-29T16:00:00Z';
$date = new DateTime($time);
echo $date->format('jS F Y');

Sample Output

Sign up to request clarification or add additional context in comments.

2 Comments

But I want the date and time should come like Tuesday, December 16, 2014 3:00 PM
@NewUser simple, just provide that format accordingly, echo $date->format('l, F d, Y g:i A'); here's the reference php.net/manual/en/function.date.php
0

You can use the DateTime class for better handling of dates

$time = '2015-06-29T16:00:00Z';
$dateTime = new DateTime($time);
echo $dateTime->format('l, F d, Y g:i A');

Comments

0
$time = '2015-06-29T16:00:00Z';
echo date( 'l, F j, Y H:i A',strtotime($time));

l, F j, Y H:i A can be re-ordered to change the output.

About date function, http://php.net/manual/en/function.date.php

Comments

0

Just pass proper format parameters to it.

$time = '2015-06-29T16:00:00Z';
echo date( 'l, F j, Y g:i A', strtotime( $time) );

2 Comments

be careful when exploding if the OP wants to preserve the zulu time, you'll get the default timezone instead
Hmm.. You are right.. but OP wants the updated answer.. So that will not matter i think.
-1

Use preg_split:

$parts = preg_plit("/Z/",$time);
$parts = preg_split("/T/",$parts[0]);
$theDate=$parts[0];
$theTime=$parts[1];
$what_you_want=date(strtotime($theDate." ".$theTime);

Note that you can still change the format of the output.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.