1$today = date("F j, Y, g:i a"); // October 30, 2019, 10:42 pm
2$today = date("D M j G:i:s T Y"); // Wed Oct 30 22:42:18 UTC 2019
3$today = date("Y-m-d H:i:s"); // 2019-10-30 22:42:18(MySQL DATETIME format)
1date_default_timezone_set('Asia/Kolkata');
2echo date("Y-m-d H:i:s"); // time in India
1# Current date
2date_default_timezone_set('Asia/Kolkata');
3echo date("Y-m-d H:i:s");
4
5# Current Time
6date_default_timezone_set("America/New_York");
7echo "The time is " . date("h:i:sa");
1phpCopy<?php
2$Object = new DateTime();
3$DateAndTime = $Object->format("d-m-Y h:i:s a");
4echo "The current date and time are $DateAndTime.";
5?>
6
1phpCopy<?php
2$DateAndTime = date('m-d-Y h:i:s a', time());
3echo "The current date and time are $DateAndTime.";
4?>
5