Test Valid Date String for JavaScript

Créé : Vendredi 31 Mai 2013 20:44:00
Mise à jour : Mardi 21 Février 2017 22:03:27

Here we check the valid strings for the argument of the Date:: class constructor to create Date object under JavaScript, ie,
<script type="text/javascript">
var objDate;
objDate = new Date("Jun 23, 2018 02:44:30 GMT+0200");
<script>
We are trying to get the PHP date format string to format date time to form the pipeline PHP DateTime() => js Date() => document.write() to output on screen. Here is the summary of cases we tested for you:
#js new Date() FeedIEChromeFirefoxSafariOperaMobile
0Jun 23, 2018 02:44:30 GMT+0200++++++
1Jun 23 2018 02:44:30 GMT+0200++++++
2Jun 23, 2018 02:44:30 GMT+2++++++
32018-06-23 02:44:30 GMT+0200-+--++
42018-06-23 02:44:30 GMT+02:00-+--++
52018-06-23 02:44:30 GMT+200-+--++
623 Jun 2018 02:44:30+02:00-+----
7Jun 23 2018 02:44:30 GMT+2:00-++-++
8Jun 23, 2018 02:44:30 GMT+02:00-++-++
92018-06-23 02:44:30 GMT+2-+--++
102018-06-23 02:44:30-+--++
112018-06-23T02:44:30+02:00+++++-
122018-06-23 02:44:30+02:00-+----
1306-23-2018 02:44:30 GMT+0200++---+
1406/23, 2018 02:44:30 GMT+0200+++-++
1523-Jun-2018 02:44:30 GMT+0200-+-+-+
Tab. I: + Valid Date Time String for Javascript::Date() class, - Invalid.

JavaScript is very English speaking. In effect, among the 3 first universal formats, the English month abbreviation is used. As it can be observed that no pure numerical date string is found like "2018-06-23 02:44:30" to fit JavaScript syntax in all browsers. Please check this with your preferred browser.

Detail of JavaScript Tests

Below, the bold date time outputs at the right hand side of => are the JavaScript Date Class results.

0. Good Format "mmm dd, yyyy hh:mm:ss GMT+0200"

For example, Jun 23, 2018 02:44:30 GMT+0200 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
0Jun 23, 2018 02:44:30 GMT+0200++++++

This format is valid for all browsers in our hands, including Internet Explorer, Google Chrome, Firefox, Safari, Opera, Mobile Safari. On PHP, you get this DateTime format of the current time by

<?php
$objDateTime = new DateTime();
$strDateTime = $objDateTime->format("M d, Y H:i:s \G\M\TO");
?>
One observes that this is the Standard English Date Time expression.

1. Another Good Format "mmm dd yyyy hh:mm:ss GMT+0200"

For example, Jun 23 2018 02:44:30 GMT+0200 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
1Jun 23 2018 02:44:30 GMT+0200++++++

This format is also valid for all browsers in our hands, including IE, Google Chrome, Firefox, Safari, Opera, Safari Mobile. On PHP, you get this DateTime format of the current time by

<?php
$objDateTime = new DateTime();
$strDateTime = $objDateTime->format("M d Y H:i:s \G\M\TO");
?>
One notes that this is another English Date Time expression with timezone.

2. Good Format "mmm dd, yyyy hh:mm:ss GMT+2"

For example, Jun 23, 2018 02:44:30 GMT+2 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
2Jun 23, 2018 02:44:30 GMT+2++++++
As shown, you can shorten the timezone notification.

Bad Formats

All following date time strings are good for some browsers, but unfortunately bad for others.

3. Format "yyyy-mm-dd hh:mm:ss GMT+0200"

For example, 2018-06-23 02:44:30 GMT+0200 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
32018-06-23 02:44:30 GMT+0200-+--++

4. Format "yyyy-mm-dd hh:mm:ss GMT+02:00"

For example, 2018-06-23 02:44:30 GMT+02:00 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
42018-06-23 02:44:30 GMT+02:00-+--++

4. Format "yyyy-mm-dd hh:mm:ss GMT+0200"

For example, 2018-06-23 02:44:30 GMT+02:00 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
52018-06-23 02:44:30 GMT+200-+--++

6. Format "dd mmm yyyy hh:mm:ss+02:00"

For example, 23 Jun 2018 02:44:30+02:00 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
623 Jun 2018 02:44:30+02:00-+----

7. Format "mmm dd yyyy hh:mm:ss GMT+02:00"

For example, Jun 23 2018 02:44:30 GMT+2:00 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
7Jun 23 2018 02:44:30 GMT+2:00-++-++

8. Format "mmm dd, yyyy hh:mm:ss GMT+02:00"

For example, Jun 23, 2018 02:44:30 GMT+02:00 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
8Jun 23, 2018 02:44:30 GMT+02:00-++-++

9. Format "yyyy-mmm-dd hh:mm:ss GMT+2"

For example, 2018-06-23 02:44:30 GMT+2 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
92018-06-23 02:44:30 GMT+2-+--++

10. Format "yyyy-mmm-dd hh:mm:ss"

For example, 2018-06-23 02:44:30 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
102018-06-23 02:44:30-+--++

11. Format "yyyy-mmm-ddThh:mm:ss+02:00"

For example, 2018-06-23T02:44:30+02:00 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
112018-06-23T02:44:30+02:00+++++-
You get this format by PHP5 DateTime=>format('c'). It's regrettable that JavaScript Mobile Safari does not support this format, as this is the universal date time string, used by SQL server, MySQL Server, ...

12. Format "yyyy-mmm-dd hh:mm:ss GMT+02:00"

For example, 2018-06-23 02:44:30+02:00 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
122018-06-23 02:44:30+02:00-+----

13. Format "mm-dd-yyyy hh:mm:ss GMT+0200"

For example, 06-23-2018 02:44:30 GMT+0200 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
1306-23-2018 02:44:30 GMT+0200++---+

14. Format "mm/dd, yyyy hh:mm:ss GMT+0200"

For example, 06/23, 2018 02:44:30 GMT+0200 =>

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
1406/23, 2018 02:44:30 GMT+0200+++-++

JavaScript new Date() running results at one single glance under CCBot/2.0 (http://commoncrawl.org/faq/)

Below, we summarize the date time feed checked above in a single table under your current browser.

#PHP DateTime->formatjs new Date() Feedjs new Date() outputs
0M d, Y H:i:s \G\M\TOJun 23, 2018 02:44:30 GMT+0200
1M d Y H:i:s \G\M\TOJun 23 2018 02:44:30 GMT+0200
2Jun 23, 2018 02:44:30 GMT+2
3Y-m-d H:i:s \G\M\TO2018-06-23 02:44:30 GMT+0200
4Y-m-d H:i:s \G\M\TP2018-06-23 02:44:30 GMT+02:00
52018-06-23 02:44:30 GMT+200
6d M Y H:i:s \G\M\TP23 Jun 2018 02:44:30+02:00
7Jun 23 2018 02:44:30 GMT+2:00
8M d Y H:i:s \G\M\TPJun 23, 2018 02:44:30 GMT+02:00
92018-06-23 02:44:30 GMT+2
10Y-m-d H:i:s2018-06-23 02:44:30
11c2018-06-23T02:44:30+02:00
12Y-m-d H:i:sP2018-06-23 02:44:30+02:00
13m-d-Y H:i:s\G\M\TO06-23-2018 02:44:30 GMT+0200
14m/d, Y H:i:s\G\M\TO06/23, 2018 02:44:30 GMT+0200
15d-M-Y H:i:s \G\M\TO23-Jun-2018 02:44:30 GMT+0200
Tab II: Real-Time JavaScript Date() Results with different Date time feed. See php.net: date — Format a local time/date.

Here the column "PHP DateTime->format" gives the format string to be used to obtain the "js new Date() Feed" column for JavaScript Date Constructor. The last column "js new Date() outputs" is JavaScript running results given by new Date(Date-Time String):

<script type="text/javascript">
document.write(new Date("Jun 23, 2018 02:44:30 GMT+0200"));
</script>

Envoyez vos commentaires (0)

Ajouter URL |
Pas encore de commentaires.
Votre commentaire :
Email
Web

Ou connexion :
Qui ?

Veuillez recopier la chaîne :
Chaîne de caractère à recopier dans la case à droite, sensible au MAJUSCULE et minuscule. Cette douleur est nécessaire après avoir reçu des milliers de messages quotidiens générés automatiquement.

Asia Home™ > Outils > Test Valid Date String for JavaScript | Conditions générales de vente | Retours et remboursements | Clauses de Confidentialité | FAQ | Google+

Envie de venir ? | Appelez-nous 7/704 67 79 04 87 (non surtaxé)

Fenêtre contextuelle    Fermer
Veuillez patienter...