将日期转换为Javascript中的字符串 [英] Convert a date to string in Javascript

查看:65
本文介绍了将日期转换为Javascript中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将Javascript Date对象转换为字符串的方法。我正在将网站从Ruby转换为服务器端Javascript,并且正在寻找类似于Ruby,C和许多其他语言的 strftime 的东西。

I'm looking for a way to convert a Javascript Date object to a string. I'm converting my site from Ruby to server side Javascript, and I'm looking for something analogous to strftime in Ruby, C, and many other languages.

我发现有很多简单的脚本可以进行这种转换,但是如果有标准的实现方法,我宁愿不包括自定义实现。

I found plenty of simple scripts that do this kind of conversion, but I'd prefer not to include a custom implementation if there is a standard way of doing this.

我没有使用Javascript框架。我正在使用Mozilla Rhino,但希望尽可能避免使用Java库,以允许在实现之间轻松移动我的代码。

I'm not using a Javascript framework. I'm using Mozilla Rhino, but would prefer to stay away from using the Java library as much as possible, to allow moving my code easily between implementations.

我想能够指定字符串的格式,因为我想将其嵌入句子中。我希望能够在和上插入任意字符,并具有当天的全名,而不仅是缩写。所以toString()不够用。

I want to be able to specify the format of the string, since I want to embed it in a sentence. I want to be able to insert arbitrary on's and at's, and have the full name of the day, not just it's abbreviation. So toString() won't suffice.

推荐答案

MomentJS 具有一组非常强大的时间格式设置选项,并且最近也进行了更新。

MomentJS has a very robust set of time formatting options, and has also been updated recently.

这篇关于将日期转换为Javascript中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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