Js date
Js date can be written as
- string Mon Aug 08 2016 12:11:50 GMT+0545 (Nepal Standard Time)
- number 1470637610203 // in milliseconds from 1970 jan 1
new Date(); // current date
new Date(86400000); // 01 January 1970 00:00:00 UTC 86400000 is one day milliseconds value
new Date (year, month, day, hours, minutes, seconds, milliseconds); // 7 param for date
new Date("October 13, 2014 11:13:00"); // date string value for date
we can also compare two date by this function.
we also have function to get days attribute... like
- day, hour, minute, second, month, year, milliseconds
date.getHours();
PHP Date
1. date(format,timestamp);
Timestamp
1. default value is Unix timestamp return by function time();
int time ( void ) ;which is - current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
2. strtotime(time,now) - strtotime("+3day"); // return 3 days after today- strtotime("2016-08-08"); // custom date
$today = date("Y-m-d H:i:s a");
$day = date("Y-m-d h:i:s a", strtotime("2016-08-08"));
It has 2 param :- date formate- date value {optional default value gives today}
y = date("Y"); // get current year
1. default value is Unix timestamp return by function time();
int time ( void ) ;which is - current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
2. strtotime(time,now) - strtotime("+3day"); // return 3 days after today- strtotime("2016-08-08"); // custom date
$today = date("Y-m-d H:i:s a");
$day = date("Y-m-d h:i:s a", strtotime("2016-08-08"));
It has 2 param :- date formate- date value {optional default value gives today}
y = date("Y"); // get current year
strtotime()
$date = "1998-08-14"; $newdate = strtotime ( '-3 month' , strtotime ( $date ) ) ; $newdate = date ( 'Y-m-j' , $newdate ); echo $newdate;
PHP DateTime
$str = "2016-11-23 13:12:36";
$dateTime = new DateTime($str);
$format = "Y-m-d H:i:s ";
return $dateTime->format($format);
or
return date_format ( DateTimeInterface $object , string $format )
or
return date_format ( DateTimeInterface $object , string $format )
Note:
JS date return current date in client system (PC clock time)
PHP date return current date of server time. (server clock time)
Current DateTime may vary with timezone
Quick note on date
src :
http://www.w3schools.com/
http://php.net/
http://www.w3schools.com/
http://php.net/