Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting current date with javascript with HTTP Date format

i'm looking for a way to get the current date and time in the HTTP date format which is for example "Tue, 15 Nov 1994 08:12:31 GMT". I would like to get that with JavaScript. I tried with:

new Date().toString()

but this gives me a different format like: "Tue Aug 20 2013 00:19:28 GMT+0200". I would need to invert the month with the day and put a coma between the day of the week and the day of the month. How can i get that format?

like image 734
giogix Avatar asked Aug 19 '13 22:08

giogix


People also ask

How can I get current date in jquery in dd mm yyyy format?

You can do it like that: var d = new Date(); var month = d. getMonth()+1; var day = d. getDate(); var output = d.

What date format is DD MMM YYYY JavaScript?

There is no native format in JavaScript for” dd-mmm-yyyy”. To get the date format “dd-mmm-yyyy”, we are going to use regular expression in JavaScript. The regular expression in JavaScript is used to find the pattern in a string. So we are going to find the “dd-mmm-yyyy” pattern in the string using match() method.


1 Answers

The HTTP date format you mention is actually an RFC-1123 timestamp. The toUTCString function on the Date object is supposed to return a compatible value.

You can validate this with this sample Fiddle.

like image 148
Niels Keurentjes Avatar answered Sep 22 '22 03:09

Niels Keurentjes