从日期字符串中获取时间 [英] Get the time from a date string

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

问题描述

如何使用JavaScript从日期字符串中获取时间。

How do I get the time from the date string using JavaScript.

我的日期字符串采用以下方式:2013-04-08T10:28:43Z

My datestring is in the following way: 2013-04-08T10:28:43Z

如何以小时和分钟格式分割时间。我希望以下列方式显示活动流:

How to split the time in hours and minutes format. I want to show the activity stream in the following way:

xxx已更新2小时前

yyy更新时间3分钟前

xxx has updated 2hrs ago
yyy has updated 3min ago

推荐答案

只需创建新的Date对象:

Just create new Date object:

var myDate = new Date("2013-04-08T10:28:43Z");

var minutes = myDate.getMinutes();
var hours = myDate.getHours();

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

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