如何从JavaScript中的此日期字符串解析年份? [英] How to parse the year from this date string in JavaScript?

查看:90
本文介绍了如何从JavaScript中的此日期字符串解析年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下字符串格式的日期:

Given a date in the following string format:

2010-02-02T08:00:00Z

如何用JavaScript获得新的一年?

How to get the year with JavaScript?

推荐答案

您可以简单地解析字符串:

You can simply parse the string:

var year = parseInt(dateString);

解析将以短划线结束,因为它不能是整数的一部分(除了第一个字符外).

The parsing will end at the dash, as that can't be a part of an integer (except as the first character).

这篇关于如何从JavaScript中的此日期字符串解析年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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