Get timestamp

7

I have two variables, one with the date and another with the time. How can I get your timestamp of the two variables. Example:

var data = 02/01/2015;
var hora = 10:00:00;
var d = new Date(data + hora);
d.getTime();
    
asked by anonymous 06.01.2015 / 17:29

3 answers

5

It's just a matter of formatting content. First you can not have the date and time so loose, you probably have string . And then you need to separate the two contents with a space.

var data = "02/01/2015";
var hora = "10:00:00";
var d = new Date(data + " " + hora);
d.getTime();

See running on JsFiddle .

    
06.01.2015 / 17:37
4

You just need to add a space in the arm to separate the time stamp.

var data = "02/01/2015 ";
var hora = "10:00:00";
var d = new Date(data + hora);
d.getTime();

The getTime method returns the timestamp in milliseconds.

I recommend reading: link

    
06.01.2015 / 17:36
1

1st Form

function TimeStamp(){
   return new Date().getTime();
} alert(TimeStamp());

2nd Form

function TimeStamp() {
    var d = new Date();
    var timestamp = d.getTime();
    return timestamp;
} alert(TimeStamp());

3rd Form

function TimeStamp() {
    return event.timeStamp;
} alert(TimeStamp());

Important! If you use getTime () to get the actual timestamp you should do the conversion below.

Math.round((new Date()).getTime() / 1000);

The getTime() returns milliseconds since the time UNIX , then divide it by 1000 to get the representation of seconds. It is rounded up using Math.round() to make it an integer. The result now has timestamp UNIX the current date and time saving for the user's browser.

    
15.10.2015 / 21:28