-2

How can I convert a date in the following format to a unix timestamp?

Thu, 26 Dec 2013 17:53:05 +0100

Thanks, Regards !

Jessica
  • 7,075
  • 28
  • 39
  • Are you trying to convert from the number to a date, or from a date to the number? – Barmar Dec 26 '13 at 16:56
  • right from date to number – user3113301 Dec 26 '13 at 16:59
  • Before your edit, the numbers in your question looked like timestamps multiplied by 1000. Now you just want normal Unix timestamps? – Barmar Dec 26 '13 at 17:04
  • Yes because the script get the data of date from this number and my script save from date(r) in db save the date as this : Thu, 26 Dec 2013 17:53:05 +0100 but need get unix timestamp , thank´s – user3113301 Dec 26 '13 at 17:08
  • You need to clarify the question. Unix timestamps are in seconds, but you want milliseconds. – Barmar Dec 26 '13 at 17:22
  • Why edit my question ? the question it´s about hihghcharsts and his microtome unis timestam all my orginal questions it´s delete and put only onle line when i don´t put that , it´s incredible , the question havehis reason because this microtome need works with this framework no only the unix timestamp incredible this moderation delete all and put the question as he want , incredible , this website it´s nazi website – user3113301 Dec 26 '13 at 21:18

3 Answers3

1

Use strtotime:

For example,

echo(strtotime("Thu, 26 Dec 2013 17:53:05 +0100"));

will output

1388076785
Jakob Weisblat
  • 7,450
  • 9
  • 37
  • 65
Jeroen Ketelaar
  • 102
  • 1
  • 6
0

strtotime will give you a unix timestamp from a date string, provided it's in a valid format.

Jessica
  • 7,075
  • 28
  • 39
0

Verbose version (oop / robust):

$dateString = 'Thu, 26 Dec 2013 17:53:05 +0100';

$date = DateTime::createFromFormat(
    DateTime::RSS, 
    $dateString,
    new DateTimeZone('UTC')
);

echo $date->getTimestamp().PHP_EOL  // 1388076785
    .$date->format('r').PHP_EOL;    // Thu, 26 Dec 2013 17:53:05 +0100

: demo

Emissary
  • 9,954
  • 8
  • 54
  • 65