Formatting and printing print dates using jquery

I need to display dates in several ways in an application built with jquery.

In some situations, I need the typical type of formatting "yyyy-mm-dd hh: mma", with all its different permutations. In other cases, I need to show β€œpretty printed” dates, similar to how StackOverflow does them:

  • 5 seconds ago
  • 12 minutes ago
  • 3 hours ago
  • yesterday
  • 2 days ago

My application already uses the jQuery UI DatePicker, which includes the formatDate () function, but as far as I can tell, there is no way to use it outside of the datepicker. I want to format dates that are not related to the dumper. Is it possible to do this with DatePicker?

The DateJS library can parse dates like β€œ12 minutes ago,” but as far as I can tell, it cannot accept date strings of an object and format like this. It can format typical yyyy-mm-dd format types. This library seems pretty heavy.

John Resig Pretty Dates looks like he can provide pretty print ("2 hours ago"), but he doesn't perform standard formatting.

Isn't there a single plugin that could do all this? Is there a way to use DatePicker code, so I don’t have to download multiple codebases that do the same thing?

+5
source share
2

prettyDate.

, jQuery Validation.

+2

All Articles