Test Valid Date String for JavaScript

Créé 2013-05-31 20:44:00
Mise à jour 2023-11-22 15:29:06

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("Apr 16, 2025 00:43:43 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
0Apr 16, 2025 00:43:43 GMT+0200++++++
1Apr 16 2025 00:43:43 GMT+0200++++++
2Apr 16, 2025 00:43:43 GMT+2++++++
32025-04-16 00:43:43 GMT+0200-+--++
42025-04-16 00:43:43 GMT+02:00-+--++
52025-04-16 00:43:43 GMT+200-+--++
616 Apr 2025 00:43:43+02:00-+----
7Apr 16 2025 00:43:43 GMT+2:00-++-++
8Apr 16, 2025 00:43:43 GMT+02:00-++-++
92025-04-16 00:43:43 GMT+2-+--++
102025-04-16 00:43:43-+--++
112025-04-16T00:43:43+02:00+++++-
122025-04-16 00:43:43+02:00-+----
1304-16-2025 00:43:43 GMT+0200++---+
1404/16, 2025 00:43:43 GMT+0200+++-++
1516-Apr-2025 00:43:43 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 "2025-04-16 00:43:43" 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, Apr 16, 2025 00:43:43 GMT+0200 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
0Apr 16, 2025 00:43:43 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, Apr 16 2025 00:43:43 GMT+0200 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
1Apr 16 2025 00:43:43 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, Apr 16, 2025 00:43:43 GMT+2 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
2Apr 16, 2025 00:43:43 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, 2025-04-16 00:43:43 GMT+0200 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
32025-04-16 00:43:43 GMT+0200-+--++

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

For example, 2025-04-16 00:43:43 GMT+02:00 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
42025-04-16 00:43:43 GMT+02:00-+--++

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

For example, 2025-04-16 00:43:43 GMT+02:00 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
52025-04-16 00:43:43 GMT+200-+--++

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

For example, 16 Apr 2025 00:43:43+02:00 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
616 Apr 2025 00:43:43+02:00-+----

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

For example, Apr 16 2025 00:43:43 GMT+2:00 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
7Apr 16 2025 00:43:43 GMT+2:00-++-++

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

For example, Apr 16, 2025 00:43:43 GMT+02:00 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
8Apr 16, 2025 00:43:43 GMT+02:00-++-++

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

For example, 2025-04-16 00:43:43 GMT+2 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
92025-04-16 00:43:43 GMT+2-+--++

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

For example, 2025-04-16 00:43:43 => Wed Apr 16 2025 00:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
102025-04-16 00:43:43-+--++

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

For example, 2025-04-16T00:43:43+02:00 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
112025-04-16T00:43:43+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, 2025-04-16 00:43:43+02:00 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
122025-04-16 00:43:43+02:00-+----

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

For example, 04-16-2025 00:43:43 GMT+0200 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
1304-16-2025 00:43:43 GMT+0200++---+

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

For example, 04/16, 2025 00:43:43 GMT+0200 => Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)

#js new Date() FeedIEChromeFirefoxSafariOperaMobile
1404/16, 2025 00:43:43 GMT+0200+++-++

JavaScript new Date() running results at one single glance under Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)

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\TOApr 16, 2025 00:43:43 GMT+0200Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
1M d Y H:i:s \G\M\TOApr 16 2025 00:43:43 GMT+0200Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
2Apr 16, 2025 00:43:43 GMT+2Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
3Y-m-d H:i:s \G\M\TO2025-04-16 00:43:43 GMT+0200Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
4Y-m-d H:i:s \G\M\TP2025-04-16 00:43:43 GMT+02:00Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
52025-04-16 00:43:43 GMT+200Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
6d M Y H:i:s \G\M\TP16 Apr 2025 00:43:43+02:00Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
7Apr 16 2025 00:43:43 GMT+2:00Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
8M d Y H:i:s \G\M\TPApr 16, 2025 00:43:43 GMT+02:00Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
92025-04-16 00:43:43 GMT+2Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
10Y-m-d H:i:s2025-04-16 00:43:43Wed Apr 16 2025 00:43:43 GMT+0000 (Coordinated Universal Time)
11c2025-04-16T00:43:43+02:00Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
12Y-m-d H:i:sP2025-04-16 00:43:43+02:00Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
13m-d-Y H:i:s\G\M\TO04-16-2025 00:43:43 GMT+0200Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
14m/d, Y H:i:s\G\M\TO04/16, 2025 00:43:43 GMT+0200Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
15d-M-Y H:i:s \G\M\TO16-Apr-2025 00:43:43 GMT+0200Tue Apr 15 2025 22:43:43 GMT+0000 (Coordinated Universal Time)
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("Apr 16, 2025 00:43:43 GMT+0200"));
</script>

Envoyez vos commentaires (14)

14. Visiteur *.*.168.* - 2024-08-20 14:30:49
Excellent write-up, I have always enjoyed your articles, you’re such an excellent writer, always on point. This article is loaded to the hilt.
13. Visiteur *.*.69.* - 2021-06-28 14:22:59
Good post guys!
12. Visiteur *.*.125.* - 2021-05-05 20:00:32
As a new online player, you will find plenty of options when it comes to online casinos. They will all claim to offer the best service, which is not necessarily true as some of them offer higher quality than others.
11. Visiteur *.*.18.* - 2021-02-17 11:50:36
If you are constantly searching for an answer to the question “Who can write my college paper for me fast and cheap?” you are in the right place. Experienced writers will help you succeed.
10. Visiteur *.*.188.* - 2021-02-07 11:39:22
We set reasonable and affordable prices for our papers. You will hardly find a better custom writing service than ours.
Email Web

Veuillez recopier la chaîne :
Texte à recopier.

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

Envie de venir ? | Appelez-nous 7/704 67 79 04 87 (Service Epices)

Fenêtre contextuelle    Fermer
Veuillez patienter...