使用jquery格式化和漂亮的打印日期 [英] Formatting and pretty printing dates with jquery

查看:106
本文介绍了使用jquery格式化和漂亮的打印日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在某些情况下,我需要典型的yyyy-mm-dd hh :mma格式的格式,它们都是不同的排列。在其他情况下,我需要显示类似于StackOverflow的日期漂亮打印:




  • 5秒前

  • 12分钟前

  • 3小时前

  • 昨天

  • 2天前



我的应用程序已经使用了包含formatDate()函数的JQuery UI DatePicker,但据我所知,没有办法在日期戳之外使用它。我想格式化与日期戳相关联的日期。可以使用DatePicker吗?



DateJS 库可以解析12分钟前的日期,但据我所知,它不能采用Date对象和格式的字符串。它可以格式化典型的yyyy-mm-dd格式的格式。这个图书馆似乎也很重。



John Resig的漂亮的日子看起来像可以提供漂亮的打印(2小时前),但它不会执行标准格式。



没有一个插件可以做到这一切吗?有没有办法利用DatePicker代码,所以我不需要加载同样的东西的多个代码库?

解决方案

http://timeago.yarp.com/


I need to display dates in a couple different ways in an app built with jquery.

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

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

My application already uses JQuery UI DatePicker which includes a 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 aren't associated with a datepicker. Is it possible to do this using DatePicker?

The DateJS library can parse dates like "12 minutes ago", but as far as I can tell, it cannot take a Date object and format strings like this. It can format the typical "yyyy-mm-dd" types of formats. This library seems pretty heavy as well.

John Resig's Pretty Dates looks like it can provide the pretty printing ("2 hours ago"), but it doesn't do the standard formatting.

Is there not a single plugin that can do all of this? Is there a way to leverage the DatePicker code so I don't have to load multiple codebases that do the same things?

解决方案

http://timeago.yarp.com/

这篇关于使用jquery格式化和漂亮的打印日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆