am new to Jquery. I want to insert current date time to Db
var data{
"id":1,
"name":"mybane",
"datetime":// here i have to put current date time
}
is there any possible way to get the current date time..
am new to Jquery. I want to insert current date time to Db
var data{
"id":1,
"name":"mybane",
"datetime":// here i have to put current date time
}
is there any possible way to get the current date time..
Use this:
var data{
"id":1,
"name":"mybane",
"datetime":new Date(),
}
Reference: How do I get the current date in JavaScript?
You are looking for this. https://stackoverflow.com/a/9050848/829533
All you need to do is to use this output
variable in your datetime:
param
var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var hour = d.getHours();
var minute = d.getMinutes();
var second = d.getSeconds();
var output = d.getFullYear() + '-' +
((''+month).length<2 ? '0' : '') + month + '-' +
((''+day).length<2 ? '0' : '') + day + ' ' +
((''+hour).length<2 ? '0' :'') + hour + ':' +
((''+minute).length<2 ? '0' :'') + minute + ':' +
((''+second).length<2 ? '0' :'') + second;
In action http://jsfiddle.net/nCE9u/3/
Other then this you can sent the direct your database related function to add current time stamp like the one CURRENT_TIMESTAMP()
(in mysql)
Note: you can send this as an string
"datetime" : "CURRENT_TIMESTAMP()"
And give it directly to the database as a string.
use new Date()
var data{
"id":1,
"name":"mybane",
"datetime":new Date()
}
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var date1 = month + "/" + day + "/" + year; // output
take your required value from below function :
getTime() - Number of milliseconds since 1/1/1970 @ 12:00 AM
getSeconds() - Number of seconds (0-59)
getMinutes() - Number of minutes (0-59)
getHours() - Number of hours (0-23)
getDay() - Day of the week(0-6). 0 = Sunday, ... , 6 = Saturday
getDate() - Day of the month (0-31)
getMonth() - Number of month (0-11)
getFullYear() - The four digit year (1970-9999)
var d=new Date();
var time=d.getTime();
This is the function you can use to get current time
Create Date object and format as you need:
var data{
"id":1,
"name":"mybane",
"datetime":(function(d) { return d.format('dd.mm.yyyy hh:MM') })(new Date());
}