 分类:
    .NET
    
    分类:
    .NET
时间处理是项目中不可缺少的,下面整理了一些常用时间处理的用法,记录一下。
原文地址:https://blog.csdn.net/ohdajing/article/details/80866209
1.获取当前时间
function getNowTime() {  
          return new Date();
           
        }2.时间与天数相加
function getTimeAddDays(time, days) 
{            
 return new Date(time.getTime() + days * 24 * 60 * 60 * 1000);
 
     }3.获取并格式化日期:年-月-日
function getFormatDate(time) 
{          return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate();
 }4.字符串转换为日期,字符串格式:2011-11-20
function convertToDate(strings) {
return new Date(Date.parse(strings.replace("-", "/")));
        }5.获取并格式化星期
 var WEEKDAYS = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; //星期 
  function getFormatWeek(time) {
             return WEEKDAYS[time.getDay()];
                     }6.时间比较
  function compareTime(time1, time2) {
              return time1.getTime() - time2.getTime();
              
                   }7.计算两个日期之间相隔的天数
function getDays(time1, tiem2)
{var day = 24*60*60*1000;return (time1.getTime() - time2.getTime())/day;
 }欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
评价
    
                    排名
                
                
                    6
                
            
                    文章
                
                
                    6
                
            
                    粉丝
                
                
                    16
                
            
                    评论
                
                
                    8
                
            
            {{item.articleTitle}}
            
    {{item.blogName}} : {{item.content}}
        
            ICP备案  :渝ICP备18016597号-1
        
        
            网站信息:2018-2025TNBLOG.NET
        
        
            技术交流:群号656732739
        
        
            联系我们:contact@tnblog.net
        
        
            公网安备: 50010702506256
50010702506256
        
     50010702506256
50010702506256
         
        
            欢迎加群交流技术
        
     
         
         
        