Adhika Trisna DP Adhika Trisna DP - 2 months ago 16
PHP Question

Set Current Timestamp with JQuery

help me to set current time, with a timestamp

var defaults = $.extend({
start: '1503113104',
end: '1505235600',
now: , // here i have to set current timestamp


thank you

Answer Source

If you wish a Unix timestamp in seconds, you have to get the time from a new Date(), divide it by 1000 (since that is in milliseconds) and remove the decimals using Math.floor().

var defaults = $.extend({
  start: '1503113104',
  end: '1505235600',
  now: Math.floor(new Date().getTime()/1000), // Unix timestamp in seconds (instead of milliseconds)

I assumed you wish it in seconds because I noticed your other times have 3 digits missing...

If you want them to be evaluated as integers... You probably should remove the quotes around them.