I
I
Ilya Beloborodov2015-10-28 16:37:40
PHP
Ilya Beloborodov, 2015-10-28 16:37:40

How to format date?

How to format a date like this 2015-10-28 13:03:12 into
Wen, 28 Oct 2015 13:03:12 +0200 ?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly Khomenko, 2015-10-28
@kowap

echo DateTime::createFromFormat( 'Y-m-d H:i:s', '2015-10-28 13:03:12' )->format( 'r' );
// Wen, 28 Oct 2015 13:03:12 +0200

echo DateTime::createFromFormat( 'Y-m-d H:i:s', '2015-10-28 13:03:12' )->format( DateTime::RFC2822 );
// Wen, 28 Oct 2015 13:03:12 +0200

echo DateTime::createFromFormat( 'Y-m-d H:i:s', '2015-10-28 13:03:12' )->format( 'D, d M Y H:i:s O' );
// Wen, 28 Oct 2015 13:03:12 +0200

or
echo date( 'r', strtotime( '2015-10-28 13:03:12' ) );
// Wen, 28 Oct 2015 13:03:12 +0200

php.net/manual/ru/datetime.createfromformat.php
php.net/manual/ru/function.strtotime.php
php.net/manual/ru/function.date.php

M
Max, 2015-10-28
@MaxDukov

date('D, d MYH:i:s O')

G
GreatRash, 2015-10-28
@GreatRash

datetime

$date = DateTime::createFromFormat('Y-m-d H:i:s', '2015-10-28 13:03:12');
echo $date->format(DateTime::RFC2822);

V
VovanZ, 2015-10-28
@VovanZ

1. Parse the date using strtotime
2. Collect the desired string representation using date
Like this:

$timestamp = strtotime("2015-10-28 13:03:12");
echo date("D, d M Y H:i:s O", $timestamp);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question