12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //1.格式化日期
- //time 日期字符串 type 从什么时候开始返回 year = 返回年月日 month = 返回月日..
- //style 样式,比如 年-月-日 年.月.日
- const getTime = function(time:string,type:string,style:Number){
- const date = new Date(time);
- const year = date.getFullYear();
- const month = date.getMonth() + 1;
- const day = date.getDate();
- //返回 年-月-日
- if(type == 'year'&& style == 1){
- return `${year}-${month}-${day}`;
- }
- //返回 年-月
- if(type == 'year'&& style == 2){
- return `${year}-${month}`;
- }
- //返回 年
- if(type == 'year'&& style == 3){
- return `${year}`;
- }
- //返回 月-日
- if(type == 'month'&& style == 1){
- return `${month}-${day}`;
- }
- //返回 月.日
- if(type == 'month'&& style == 2){
- return `${month}.${day}`;
- }
- //返回 日
- if(type == 'day'&& style == 1){
- return `${day}`;
- }
- }
- //2.格式化标题长度
- //title 标题 length 长度
- const getTitleLength = function(title:string,length:number){
- if(title.length >= length){
- return title.substring(0, length) + "...";
- }else{
- return title;
- }
- }
- export { getTime,getTitleLength };
|