Jump to content

javascript Unix Time


StirCrazy

Recommended Posts

I'm trying to get unix time based on data inputted into a drop down menu: example code below:-

 

 

<select id="dateselector" value="day" class="datedropdown">
<option onChange="updateDate();" value="01" name="inDay" >1</option>
<option onChange="updateDate();" value="02" name="inDay" >2</option>
<option onChange="updateDate();" value="03" name="inDay" >3</option>
<option onChange="updateDate();" value="04" name="inDay" >4</option>
...
<select id="dateselector" value="month" class="datedropdown">
<option onChange="updateDate();" value="01" name="inMon" >January</option>
<option onChange="updateDate();" value="02" name="inMon" >February</option>
<option onChange="updateDate();" value="03" name="inMon" >March</option>
...
<select id="dateselector" value="year" class="datedropdown">
<option onChange="updateDate();" value="06" name="inYear" >2006</option>
<option onChange="updateDate();" value="07" name="inYear" >2007</option>
...

 

 

I have no idea how to get the updateDate() function to output unix time into 'var timestamp' as i have very little experience with .js

 

 

I'm guessing it looks a little like:-

 

function updateDate() {

    var timestamp = new Date(Date.UTC(document.getElementsByName("inYear").value,
          (stripLeadingZeroes(document.getElementsByName("inMon").value)-1),
           stripLeadingZeroes(document.getElementsByName("inDay").value),
           0, 0, 0));
           timestamp=timestamp.getTime()/1000.0;
	   updateText();
}

 

(updateText(); then updates a text area)

 

Any help to with the correct syntax would be great.

 

Thanks in advance  :)

 

S.C>

Link to comment
https://forums.phpfreaks.com/topic/45973-javascript-unix-time/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.