【问题标题】:Javascript: two buttons set two timestampJavascript:两个按钮设置两个时间戳
【发布时间】:2013-06-25 04:26:44
【问题描述】:

我有一个表单,有两个文本输入(两个时间戳)如下:

时间戳开始 [] 时间戳结束[]

两个时间戳都将使用两个按钮自动填充: [Set Start] 和 [Set End],以格式(24h)读取本地时间戳:

2013-06-27 23:55

TimeStamp start 是操作员开始填写表格的时间,而 TimeStamp end 是表单结束填写的时间(这些事件之间的延迟也可以是 1 小时)

然后通过 POST 将数据处理到脚本 PHP

如何在客户端(JS、JQuery?)处理这个时间戳设置

提前致谢

@manraj82

我发现这个 JS 函数可以用 JS 获取时间戳

function getTimeStamp() { 
    var now = new Date(); 
    return ((now.getMonth() + 1) + '/' + (now.getDate()) + '/' + now.getFullYear() + "   
    " + now.getHours() + ':' + ((now.getMinutes() < 10) ? ("0" + now.getMinutes()) :  
    (now.getMinutes())) + ':' + ((now.getSeconds() < 10) ? ("0" + now.getSeconds()) : 
    (now.getSeconds()))); 
 }

现在我必须将它关联到两个按钮

【问题讨论】:

  • 你有试过的代码吗?
  • 找到上面的js函数获取时间戳:

标签: javascript forms text input timestamp


【解决方案1】:

我不太明白你的问题是什么,但试试这个。这可能不是答案,但会给你一个想法

Date.prototype.addHours= function(h){
    var newDateTime = new Date(this);

    newDateTime.setHours(newDateTime.getHours() + h);
    return newDateTime;
}

function getTimeStamp(dt) { 
    return (
    (dt.getMonth() + 1) + '/' + 
    (dt.getDate()) + '/' + dt.getFullYear() +
    " " + 
     dt.getHours() + ':' + 
    ((dt.getMinutes() < 10) ? ("0" + dt.getMinutes()) : (dt.getMinutes())) + ':' + 
    ((dt.getSeconds() < 10) ? ("0" + dt.getSeconds()) : (dt.getSeconds()))); 
 }


var startDateTime = new Date(),
    addHours = 10,
    endDateTime = startDateTime.addHours(addHours);

console.log(getTimeStamp(startDateTime));
console.log(getTimeStamp(endDateTime));

【讨论】:

    猜你喜欢
    • 2019-02-27
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 2017-05-12
    相关资源
    最近更新 更多