字符串截取有关问题

WBOY
Release: 2016-06-13 13:52:36
Original
723 people have browsed it

字符串截取问题
19850523怎么变成1985-05-23这样的形式呢?
我现在的做法是用了三次substr()
有简单的办法么?

------解决方案--------------------
正则表达式:

var s = "19850516 ";
s = s.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3 ");
alert(s);
------解决方案--------------------
看样子是日期字符串,不妨利用date函数
$str = '19850523 ';
echo date( 'Y-m-d ',strtotime($str));

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!