Reputation: 2617
First Part of the Question :
When I m using new Date ();
in Javascript.
it gives
Fri Jun 19 2015 11:18:02 GMT+0530 (India Standard Time)
This is giving my local machine time.whereas server time is 7 mins ahead.
Is there any function which gives server time not local machine time same exactly as new Date()
But from server not localMachine.
In My project i am using codeigniter.is there any method to keep datetime same as servertime not localmachine time.
so when i use echo date('Y-m-d H:i:s')
. This gives server time.
Second part of the question :
How to echo date in php in the same format like new Date()
in Javascript:
new Date()
Prints Fri Jun 19 2015 11:18:02 GMT+0530 (India Standard Time)
But in Php date('D M Y G:i:s T', time());
is giving Fri Jun 19 2015 11:18:02 IST
How to achieve same format like new Date()
.
Upvotes: 2
Views: 2517
Reputation: 535
If you work on real server I believe you can get proper time by this snippet.
function server_time()
{
$this->load->helper('date');
echo now();
echo "<br>";
}
If you use xampp or wamp on your local pc that time you'll get your local pc time.
Upvotes: 3
Reputation: 3743
Create an ajax script which will retrieve server time
function server_time()
{
$this->load->helper('date');
echo now(); // UNIX timestamp
}
Then convert it in desired format with javascript
var date = new Date(response*1000);
Upvotes: 1