Reputation: 1389
I'd like to check the timestamp of the form submission. I'm trying to get the timeStamp
of the event but that returns the 1/1/1970 date always. How to do that correctly?
$('#form').on('submit', (event) => {
console.log(new Date(event.timeStamp).toLocaleDateString("en-UK"))
})
body {
background: white; /* try type yellow */
color: #323232;
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
font-family: Helvetica neue, roboto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="form">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
Upvotes: 0
Views: 953
Reputation: 894
Use new Date().toLocaleDateString("en-UK"), and forget the timestamp from the event. It will give you the result you're looking for.
Upvotes: 2