lolalola
lolalola

Reputation: 3823

jquery, work with date

how in jQuery work date? I want to perform mathematical operations to date.

var date = '2010-11-23 21:32:31';
var date = date - 70;
alert(date);

how get: 2010-11-23 21:31:21

Thanks

Upvotes: 2

Views: 4604

Answers (2)

Chris Conway
Chris Conway

Reputation: 16519

This is not really a jQuery question as it is more a javascript question. For that answer, have a look at this: http://www.w3schools.com/jsref/jsref_obj_date.asp.

Upvotes: 0

Fábio Batista
Fábio Batista

Reputation: 25260

Try:

http://www.datejs.com/

It's not jQuery, but will solve your problems.

From their sample page:

// What date is next thrusday?
Date.today().next().thursday();

// Add 3 days to Today
Date.today().add(3).days();

// Is today Friday?
Date.today().is().friday();

// Number fun
(3).days().ago();

// 6 months from now
var n = 6;
n.months().fromNow();

// Set to 8:30 AM on the 15th day of the month
Date.today().set({ day: 15, hour: 8, minute: 30 });

// Convert text into Date
Date.parse('today');
Date.parse('t + 5 d'); // today + 5 days
Date.parse('next thursday');
Date.parse('February 20th 1973');
Date.parse('Thu, 1 July 2004 22:30:00');

Upvotes: 6

Related Questions