简体   繁体   English

从字符串中删除最后9个字符,然后重新格式化剩余的日期字符

[英]Removing last 9 characters from a string and then reformatting the remaining date characters

My question has 2 parts. 我的问题分为两部分。 First I would like to remove the last 9 characters from a generated string using jQuery eg 首先,我想使用jQuery从生成的字符串中删除最后9个字符,例如

2011-04-04T15:05:54 2011-04-04T15:05:54

which would then leave the date remaining. 然后将剩下剩余的日期。 I know to use the .substring function. 我知道使用.substring函数。 After the time is removed I need to reformat the date into this format 时间删除后,我需要将日期重新格式化为这种格式

08.04.11 (for eg) 08.04.11(例如)

I am learning how to write jQuery and would appreciate any help with this code. 我正在学习如何编写jQuery,并希望对此代码有任何帮助。

This is what you do with pure javascript, jQuery is not needed. 这就是您使用纯JavaScript所做的事情,不需要jQuery。

var d1=new Date();
d1.toString('yyyy-MM-dd');       //returns "2009-06-29"
d1.toString('dddd, MMMM ,yyyy')  //returns "Monday, June 29,2009"

Another example to fit your case: 另一个适合您的情况的示例:

var d1=new Date();
d1.toString('dd.MM.yy');       //returns "08.04.11"

More: 更多:

Where can I find documentation on formatting a date in JavaScript? 在哪里可以找到有关在JavaScript中格式化日期的文档?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM