English 中文(简体)
如何将 javascript 时间对象转换为不同格式?
原标题:how to convert javascript time object to different format?
    tableHTML += "<td class="stamp">"+jsonObject[i][ stamp ]+"</td>";

这里正在显示 2012-05- 25 23: 08: 57 如何修改为 May 25,2012

一位评论员指出,用php做这件事可能更好,只有用php做才可能。这是可能的吗?

$videos_array = array();
while ($i < $num) {
$current_video = array (
 stamp =>mysql_result($result,$i,"stamp"));
array_push($videos_array, $current_video);
        $i++;
    }
    echo json_encode($videos_array);
最佳回答

使用真正的约会图书馆 就像德德勒医生建议的那样 但如果你想黑黑的话 总会有

new Date(Date.parse("2012-05-25 23:08:57")).toDateString().substring(4)

不用于严重代码中。 它依赖于本地端 < code> toDateString 的输出。 这样做的正确方式是使用日期对象, 就在您显示日期对象之前, 请选择 < em> dated 格式

JavaScript 中的内置日期对象没有做好此工作 。

您可以在"https:// developmenter.mozilla.org/en/JavaScript/Reference/Global_Objects/Date" rel=“nofollow”中找到使用它的例子,MDN documents

< 强 > 增编 < /强 >

好了,我开始严肃地用datejs来做一个例子。你可以找到一个现场工作版本这里

基本上,在您的 HTML 中加入以下内容:

<script src="http://cachedcommons.org/cache/datejs/1.0.0/javascripts/date-min.js"></script>

调 Then in your JavaScript adapt the following code:

var d = Date.parse("2012-05-25 23:08:57");
alert(d.toString("MMM dd, yyyy"));

问题回答

我强烈建议使用 Date.js http://www.datejs.com/ ,尽管显然对于这样简单的事情,你可以很快地自行滚动。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签