1

it's the first time I have to deal with localization in JS. Turned out JS has not something like PHP's date time format ($date->format('Y-m-d H:i:s')). Yes, it has format() but this method has no arguments.

I have no idea what to do know. I need to set a format string and I am shocked that there is no native support for this.

Solutions? Any JS libs that solve it?

knightsb
  • 337
  • 3
  • 11
chris342423
  • 439
  • 1
  • 6
  • 22

3 Answers3

2

You could try one of the many existing javascript libraries and code snippets. For example

  1. DateJS http://code.google.com/p/datejs/wiki/FormatSpecifiers
  2. FormatDate http://www.dzone.com/snippets/javascript-formatdate-function
  3. Date.format prototype extension http://www.jslab.dk/library/date.format
  4. XDate http://arshaw.com/xdate/
  5. KendoUI http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting
  6. AngularJS http://docs.angularjs.org/api/ng/filter/date
  7. Google Apps Script https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)
  8. Globalize https://github.com/jquery/globalize#format_date

and many many other...

Zlatin Zlatev
  • 3,034
  • 1
  • 24
  • 32
2

Here's a list of some great Date formatting libraries:

  1. DateJs - Datejs is an open-source JavaScript Date Library
  2. MomentJs - A javascript date library for parsing, validating, manipulating, and formatting dates.
  3. JQuery UI DateTime - JQuery UI DateTime library
  4. Xdate - A Modern JavaScript Date Library
  5. DP_DateExtensions - The DP_DateExtensions library extends the JavaScript Date object with new features and functionality.
Alex Choroshin
  • 6,177
  • 2
  • 28
  • 36
1

Date.js

This is an excellent library which will do what your looking for. Check out the .toString(specifier) API to format it's output.

Dan C
  • 35
  • 3