2

I am trying to insert local time into database using javascript. Can any one help me? could you please have a look on the file named member.class.php and please let me know where I have to put the javascript code... https://www.dropbox.com/sh/lfef67brewx7rub/wYRP72bDh7

user1946440
  • 349
  • 1
  • 5
  • 13

5 Answers5

0

Its very simple man...try with this

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

it will give you time in milli seconds or you can use like

new Date().getTime();

if you want it in unix(linux) timestamp then use like this

var unix = Math.round(+new Date()/1000);   it will also give you in seconds
GautamD31
  • 28,552
  • 10
  • 64
  • 85
  • What about date and time together? and I am trying to store it in linux platform in web host... – user1946440 Feb 08 '13 at 11:56
  • could you please have a look on the file named member.class.php and please let me know where I have to put the javascript code... `https://www.dropbox.com/sh/lfef67brewx7rub/wYRP72bDh7` – user1946440 Feb 08 '13 at 12:19
0

In Javascript:

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

In PHP, the best way will be that you should create your time column DATETIME type and set default value CURRENT_TIMESTAMP. No need to manually insert it through Javascript.

sohel khalifa
  • 5,602
  • 3
  • 34
  • 46
  • after setting current_timestamp the value is inserting the servers current time... but I want to insert my local regions time – user1946440 Feb 08 '13 at 11:58
  • could you please have a look on the file named member.class.php and please let me know where I have to put the javascript code... `https://www.dropbox.com/sh/lfef67brewx7rub/wYRP72bDh7` – user1946440 Feb 08 '13 at 12:17
0
var currentdate = new Date(); 
var datetime = "Date n Tym : " + currentdate.getDate() + "/"
            + (currentdate.getMonth()+1)  + "/" 
            + currentdate.getFullYear() + " @ "  
            + currentdate.getHours() + ":"  
            + currentdate.getMinutes() + ":" 
            + currentdate.getSeconds();
Sekhar
  • 21
  • 7
0

10 ways to format time and date using JavaScript

See this answer!

Community
  • 1
  • 1
Giovanne Afonso
  • 666
  • 7
  • 21
0

DB like time stamp in 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);

after this, for example, timestamp="20160408-134304"

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345