Writing small utility functions such as this is also a useful exercise for both beginning and accomplished programmers alike and can be a learning experience for the novices amongst us. In this case a general purpose library seems overkill, unless other parts of the application process dates heavily. I have nothing against libraries in general. To escape characters, wrap them in square brackets (e.g. Datejs - not packaged in npm or GitHub so not quite so easy to use with Node - not really recommended as not updated since 2007! Get the formatted date according to the string of tokens passed in.Tempus - UPDATE: this can also be used with Node and deployed with npm, see the docs.Time Traveller only extends date objects that it creates, without polluting the global namespace." From adding and subtracting, to formatting. TimeTraveller - "Time Traveller provides a set of utility methods to deal with dates.dateutil - This is the one I used to use before MomentJS How to Format Date in JavaScript Most developers, at some point in their career, will need to handle the very common task of formatting a time or date in JavaScript.strftime - Just what it says, nice and simple.In implementations with Intl.DateTimeFormat, this is equivalent to new Intl.DateTimeFormat (locales, options).format (date), where options has been normalized as described above. Includes some excellent looking date/time capabilities. A string representing the date portion of the given Date instance according to language-specific conventions. SugarJS - A general helper library adding much needed features to JavaScripts built-in object types.Great alternative to Moment if you don't need timezone support. date-fns Small, fast, works with standard JS date objects.Update : No longer in active development. Moment.js "A lightweight (4.3k) javascript date library for parsing, manipulating, and formatting dates" - Includes internationalization, calculations and relative date formats - Update : Not quite so light-weight any more but still the most comprehensive solution, especially if you need timezone support.Luxon "A powerful, modern, and friendly wrapper for JavaScript dates and times." - MomentJS rebuilt from the ground up with immutable types, chaining and much more.Day.js "Fast 2kB alternative to Moment.js with the same modern API".Here is a list of the main Node compatible time formatting libraries: There are lots of edge cases in date/time calculations so it is useful to be able to hand-off the development to a library. OK, since no one has actually provided an actual answer, here is mine.Ī library is certainly the best bet for handling dates and times in a standard way. UPDATE : Added SugarJS which seems to have some excellent date/time functions. UPDATE : Added date-fns, some notes on Moment and Datejs The website has some recommendations for alternatives and an explanation of why. It won't disappear in a hurry because it is embedded in so many other things. UPDATE : Added Day.js and remove spurious edit by : Luxon added by : It should now be noted that Moment.js is no longer being actively developed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |