仅获取日期的时间戳,反之亦然
Get time stamp only for date and vice versa
我在 SO 中搜索过,但没有找到我的答案。
这是我的查询,在javascript中我们通常生成如下时间戳
Date.now()
输出类似于 1424592736769
但是这个值每次都会改变,因为时间与它相关联。
例如假设我今天生成时间戳并存储在数据库中....几天后如果我以 2012, 01, 1
格式输入日期,我应该能够获得相同的时间戳。
我试过的
//got time stamp
var a = Date.now() / 1000000 | 0
var d = Date(a);
console.log(d);
// 现在基于 var a ,我可以根据指定的日期格式生成时间戳
我知道错了,请大神指教
P.S :我做这个操作是因为我想在 particular date
上存储一个 数据 作为数据库中的时间戳并修改那些 data 稍后基于 that particular date
通过时间戳。
例如我的数据库应该是这样的
DAY DATA
------------------
432324234 - 1000 rs //day1 data
767677657 - 2000 rs //day2 data
P.s : 没有人理解我的问题,更清楚
我需要获取今天的日期(例如,2015 年 2 月 22 日)作为时间戳,如果我使用 Date(2015,01,22) 几天后,我必须获取 2015 年 2 月 22 日生成的相同时间戳
根据我对您尝试执行的操作的理解,像这样删除 new
关键字会将 d
设置为时间戳 [=] 的 Date
对象15=]:
//got time stamp
var a = Date.now() / 1000000 | 0
var d = Date(a);
console.log(d);
编辑
根据这篇文章:convert date to timestamp in javascript? 要从日期获取时间戳,请执行以下操作:
var timestamp = new Date(myDate).getTime();
a = new Date(Date.now());
d = new Date(a.getFullYear(), a.getMonth(), a.getDate()).getTime();
I need to get todays date for example (feb 22 2015) as time stamp , After few days if I use Date(2015,22,2) , I must get the same time stamp generated on feb 22 2015
注意构造函数格式是 Date(yyyy,mm,dd) 所以今天是:Date(2015,02,22)。
我在 SO 中搜索过,但没有找到我的答案。
这是我的查询,在javascript中我们通常生成如下时间戳
Date.now()
输出类似于 1424592736769
但是这个值每次都会改变,因为时间与它相关联。
例如假设我今天生成时间戳并存储在数据库中....几天后如果我以 2012, 01, 1
格式输入日期,我应该能够获得相同的时间戳。
我试过的
//got time stamp
var a = Date.now() / 1000000 | 0
var d = Date(a);
console.log(d);
// 现在基于 var a ,我可以根据指定的日期格式生成时间戳 我知道错了,请大神指教
P.S :我做这个操作是因为我想在 particular date
上存储一个 数据 作为数据库中的时间戳并修改那些 data 稍后基于 that particular date
通过时间戳。
例如我的数据库应该是这样的
DAY DATA
------------------
432324234 - 1000 rs //day1 data
767677657 - 2000 rs //day2 data
P.s : 没有人理解我的问题,更清楚
我需要获取今天的日期(例如,2015 年 2 月 22 日)作为时间戳,如果我使用 Date(2015,01,22) 几天后,我必须获取 2015 年 2 月 22 日生成的相同时间戳
根据我对您尝试执行的操作的理解,像这样删除 new
关键字会将 d
设置为时间戳 [=] 的 Date
对象15=]:
//got time stamp
var a = Date.now() / 1000000 | 0
var d = Date(a);
console.log(d);
编辑 根据这篇文章:convert date to timestamp in javascript? 要从日期获取时间戳,请执行以下操作:
var timestamp = new Date(myDate).getTime();
a = new Date(Date.now());
d = new Date(a.getFullYear(), a.getMonth(), a.getDate()).getTime();
I need to get todays date for example (feb 22 2015) as time stamp , After few days if I use Date(2015,22,2) , I must get the same time stamp generated on feb 22 2015
注意构造函数格式是 Date(yyyy,mm,dd) 所以今天是:Date(2015,02,22)。