English 中文(简体)
日期改为天数,然后做 st
原标题:convert date to number of days then do stuff
  • 时间:2011-11-20 23:06:29
  •  标签:
  • javascript

我希望用户能够进入日期。 采用一种形式,并在这种背景下将这种形式改为天数。 之后又放下了几天时间,然后将该日期改为日期。

例:

出生日期。

- 折合日数(日期)

然后,将新的总数改为:

新总数改为日期。

Can anyone point me in the right direction of doing this, or do they know some function for doing this?

So lets say :user enters date 13th July 1980 We use js to convert this to total number of days 11,453 days

Then create new function : subtotal=11453-280

并将这些天数改为日期,并在屏幕上重复。

最佳回答
var d1 = Date.parse("13 July 1980");
d1 = d1 - 24192000000; // 280 days in milliseconds

var newDate = new Date(d1);

console.log(newDate); // will return a date object that represents Oct 07 1979

Then use the following link to format it: http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3

Thanks to this SO question for the link: Where can I find documentation on formatting a date in JavaScript?

问题回答

日期用途物体。 利用工厂进行转换。 因此,如果你拿到日mill,然后拖拉或增加日子 * 86400 * 1 000,然后制造另一日期标。

var d2 = new Date (d1.getTime() - days_to_subtract * 86400 * 1000);

This might help... http://www.w3schools.com/jsref/jsref_obj_date.asp

Why the conversion to and from days? To add or subtract days, just add or subtract them from the date:

// New date object for 15 November, 2011
var d = new Date(2011, 10, 15);

// Add 5 days
d.setDate(d.getDate() + 5);  // 20-Nov-2011

// Subract 200 days
d.setDate(d.getDate() - 200); // 4-May-2011




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签