Mag*_*zad 8 javascript jquery date
我想问一下是否有人知道如何从以下示例中删除日期名称,警报返回 2020 年 2 月 29 日星期六,我不使用 Moment.js 仅 Jquery,因为我只需要能够以以下格式处理日期下面写成代码。
var mydate = new Date('29 Feb 2020');
alert(mydate.toDateString());
Run Code Online (Sandbox Code Playgroud)
感谢您阅读这个问题,希望我清楚我的问题是什么
Pra*_*lan 21
该Date#toDateString
方法将导致始终以该特定格式返回。
因此,要么您需要使用其他可用方法生成,要么您可以使用多种方法删除,
String#split
,Array#slice
和Array#join
var mydate = new Date('29 Feb 2020');
// split based on whitespace, then get except the first element
// and then join again
alert(mydate.toDateString().split(' ').slice(1).join(' '));
Run Code Online (Sandbox Code Playgroud)
String#replace
var mydate = new Date('29 Feb 2020');
// replace first nonspace combination along with whitespace
alert(mydate.toDateString().replace(/^\S+\s/,''));
Run Code Online (Sandbox Code Playgroud)
String#indexOf
和String#substr
var mydate = new Date('29 Feb 2020');
// get index of first whitespace
var str = mydate.toDateString();
// get substring
alert(str.substr(str.indexOf(' ') + 1));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7796 次 |
最近记录: |