1
2<?php
3$date = new DateTime('2000-01-01');
4echo $date->format('Y-m-d H:i:s');
5?>
6
7
1phpCopy$theDate = new DateTime('2020-03-08');
2echo $stringDate = $theDate->format('Y-m-d H:i:s');
3
4//output: 2020-03-08 00:00:00
5
1phpCopy$date = date_create_from_format('d M, Y', '08 Mar, 2020');
2echo $newFormat = date_format($date,"Y/m/d H:i:s");
3
4//output: 2020/03/08 00:00:00
5
1phpCopy$dateFormat = new DateTime(); // this will return current date
2echo $stringDate = $date->format(DATE_ATOM);
3
4//output: 2020-03-08T12:54:56+01:00
5
1phpCopy$date = explode("/",date('d/m/Y/h/i/s')
2list($day,$month,$year,$hour,$min,$sec) = $date);
3echo $month.'/'.$day.'/'.$year.' '.$hour.':'.$min.':'.$sec;
4
5//output: 03/08/2020 02:01:06
6
1phpCopydefine ('DATE_ATOM', "Y-m-d\TH:i:sP");
2define ('DATE_COOKIE', "l, d-M-y H:i:s T");
3define ('DATE_ISO8601', "Y-m-d\TH:i:sO");
4define ('DATE_RFC822', "D, d M y H:i:s O");
5define ('DATE_RFC850', "l, d-M-y H:i:s T");
6define ('DATE_RFC1036', "D, d M y H:i:s O");
7define ('DATE_RFC1123', "D, d M Y H:i:s O");
8define ('DATE_RFC2822', "D, d M Y H:i:s O");
9define ('DATE_RFC3339', "Y-m-d\TH:i:sP");
10define ('DATE_RSS', "D, d M Y H:i:s O");
11define ('DATE_W3C', "Y-m-d\TH:i:sP");
12