2013-02-08 123 views
1

我想使用JavaScript将当地时间插入到数据库中。谁能帮我? 请你对文件命名member.class.php看看,并请让我知道我必须把javascript代码... https://www.dropbox.com/sh/lfef67brewx7rub/wYRP72bDh7在数据库中使用javascript插入当前时间戳使用php

+0

其实我已经试着用PHP脚本,但我没有那么多熟悉JavaScript – user1946440 2013-02-08 11:54:15

+0

一小段代码可以帮助我们帮助你。 – MarcDefiant 2013-02-08 11:59:44

回答

0

它非常简单的人......试着用这个

var milliseconds = new Date().getTime(); 

它会给你时间以毫秒秒,如果你想在UNIX(Linux)的时间戳,您可以使用像

new Date().getTime(); 

然后使用这样

var unix = Math.round(+new Date()/1000); it will also give you in seconds 
+0

怎么样在一起的日期和时间?我试图将它存储在Linux平台的网络主机... – user1946440 2013-02-08 11:56:29

+0

嗨考虑你编辑 – Gautam3164 2013-02-08 11:59:09

+0

你可以请看看名为member.class.php的文件,请让我知道我必须把JavaScript代码...'https:// www.dropbox.com/sh/lfef67brewx7rub/wYRP72bDh7' – user1946440 2013-02-08 12:19:05

0

在Javascript中:

var d = new Date(); 
    var date_with_time = d.getDate()+"-" 
         +d.getMonth()+1+"-" 
         +d.getFullYear()+" " 
         +d.getHours()+" " 
         +d.getMinutes()+" " 
         +d.getSeconds(); 

在PHP中,最好的办法将是你应该创建timeDATETIME类型和设置默认值CURRENT_TIMESTAMP。无需通过Javascript手动插入。

+0

设置current_timestamp后,该值正在插入服务器当前时间...但我想插入我的本地区域时间 – user1946440 2013-02-08 11:58:26

+0

可否请您有一个看看名为member.class.php的文件,请让我知道我必须把javascript代码放在哪里......'https:// www.dropbox.com/sh/lfef67brewx7rub/wYRP72bDh7' – user1946440 2013-02-08 12:17:42

0
var currentdate = new Date(); 
var datetime = "Date n Tym : " + currentdate.getDate() + "/" 
      + (currentdate.getMonth()+1) + "/" 
      + currentdate.getFullYear() + " @ " 
      + currentdate.getHours() + ":" 
      + currentdate.getMinutes() + ":" 
      + currentdate.getSeconds(); 
0

DB像时间戳JS:

var timestamp = "" + d.getFullYear() 
        + ("0" + (d.getMonth()+1)).slice(-2) 
        + ("0" + d.getDate()).slice(-2) + "-" 
        + ("0" + d.getHours()).slice(-2) 
        + ("0" + d.getMinutes()).slice(-2) 
        + ("0" + d.getSeconds()).slice(-2); 

在此之后,例如,时间戳=“20160408-​​134304”

相关问题