我在几个地方见过这个
function fn() {
return +new Date;
}
Run Code Online (Sandbox Code Playgroud)
我可以看到它返回的是时间戳而不是日期对象,但我找不到有关加号正在做什么的任何文档.
谁能解释一下?
如何为javascript日期对象timeObject添加10秒.我认为这样的事情......
var timeObject = new Date()
var seconds = timeObject.getSeconds() + 10;
timeObject = timeObject + seconds;
Run Code Online (Sandbox Code Playgroud) 如何将此伪代码转换为工作js [不要担心结束日期的来源,除非它是一个有效的javascript日期].
var myEndDateTime = somedate; //somedate is a valid js date
var durationInMinutes = 100; //this can be any number of minutes from 1-7200 (5 days)
//this is the calculation I don't know how to do
var myStartDate = somedate - durationInMuntes;
alert("The event will start on " + myStartDate.toDateString() + " at " + myStartDate.toTimeString());
Run Code Online (Sandbox Code Playgroud) 我可以得到这样的当前日期对象:
var currentDate = new Date();
Run Code Online (Sandbox Code Playgroud)
我怎么能加20分钟呢?
var twentyMinutesLater = ?;
Run Code Online (Sandbox Code Playgroud) 所以,我正在尝试为图形添加一些标签,我想在水平轴上将它们添加到6,12,18和24小时.
我想以"hh:mm"格式(例如23:10,10:10,11:10和17:10)为本地(计算机)时区写这些时间?
有人可以帮我弄这个吗?
我开始使用mongodb,我正在尝试查询具有此文档格式的数据库:
{ "_id" : ObjectId("520b8b3f8bd94741bf006033"), "value" : 0.664, "timestamp" : ISODate("2013-08-14T13:48:35Z"), "cr" : ISODate("2013-08-14T13:50:55.834Z") }
Run Code Online (Sandbox Code Playgroud)
我可以使用此查询从日期时间获取最后的记录:
> db.mycol.find({timestamp:{$gt: ISODate("2013-08-14T13:48:00Z")}}).sort({x:1});
Run Code Online (Sandbox Code Playgroud)
但是我试图从18分钟前获得一个带有值字段和时间戳的集合,我该如何为此构建查询?谢谢大家耐心等待...
基本上我需要显示到指定时间的时间或者它是否通过了多长时间,它过了多长时间.
原始字符串看起来像这样: 07/20/2011 01:13 am
编辑:从在javascript转换到PHP切换:
//get local time in UTC format
echo gmdate("Y/m/d\TH:i:s\Z");
echo '<br />';
//convert time to UTC
$the_date = strtotime("07/20/2011 01:13 am");
echo date("Y/m/d\TH:i:s\Z",$the_date);
Run Code Online (Sandbox Code Playgroud)
执行上述操作后,我可以使用以下内容:
//local time
2011/07/20T19:49:39Z
//specified time
2011/07/20T01:13:00Z
Run Code Online (Sandbox Code Playgroud)
如何获取指定的时间和当地时间并使其显示如下示例:
Started 36 mins ago
Will start in 33 mins
Will start in 6 hrs 21 mins
Will start in 4 days 4 hrs 33 mins
Run Code Online (Sandbox Code Playgroud) 我现在的日期如下:
var now = new Date();
Run Code Online (Sandbox Code Playgroud)
我想在现有时间增加5分钟.时间是12小时格式.如果时间是凌晨3:46,那么我希望凌晨3:51.
function DateFormat(date) {
var days = date.getDate();
var year = date.getFullYear();
var month = (date.getMonth() + 1);
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = days + '/' + month …Run Code Online (Sandbox Code Playgroud) var time="18:15:00"
我正在以24小时格式获得时间,如上面的字符串.我必须添加15分钟的时间我如何添加.不使用substring().
var time 字符串不是date object.在谷歌搜索但没有得到它.
如何以 15 分钟的时间间隔运行 Javascript 循环?它应该使用 24 小时格式。例如,从早上 6:00 到晚上 11:45 运行,它将在 6:00、6:15、6:30 --- 23:45 等运行。这些值在 html 中显示为下拉菜单项。我将记事本用于 javascript 和 html,因为我需要这样做。