asp 時間日期格式化程式

來源:互聯網
上載者:User

'函數名:FormatTime
  '作  用:時間格式化
  '參  數:DateTime ----要格式化的時間
  '       Format   ----格式的形式
  '****************************************************
  Public Function FormatTime(DateTime,Format)
   select case Format
   case "1"
  FormatTime=""&year(DateTime)&"年"&month(DateTime)&"月"&day(DateTime)&"日"
   case "2"
  FormatTime=""&month(DateTime)&"月"&day(DateTime)&"日"
   case "3"
  FormatTime=""&year(DateTime)&"/"&month(DateTime)&"/"&day(DateTime)&""
   case "4"
  FormatTime=""&month(DateTime)&"/"&day(DateTime)&""
   case "5"
  FormatTime=""&month(DateTime)&"月"&day(DateTime)&"日"&FormatDateTime(DateTime,4)&""
   case "6"
   temp="周日,周一,周二,周三,周四,周五,周六"
   temp=split(temp,",")
   FormatTime=temp(Weekday(DateTime)-1)
   case Else
   FormatTime=DateTime
   end select
  End Function
 
 Public Function TimeToDiff(DateTime)
  If IsDate(DateTime) Then
   Dim tSecond:tSecond=DateDiff("s",DateTime,Now())
   If tSecond<60 Then'//一分鐘內
    TimeToDiff="剛剛"
   End If
   If tSecond>=60 And tSecond<3600 Then'//一小時內
    TimeToDiff=DateDiff("n",DateTime,Now())&"分鐘前"
   End If
   If tSecond>=3600 And tSecond<86400 Then'//一天內
    TimeToDiff=DateDiff("h",DateTime,Now())&"小時前"
   End If
   If tSecond>=86400 And tSecond<2592000 Then'//一個月內
    TimeToDiff=DateDiff("d",DateTime,Now())&"天前"
   End If
   If tSecond>=2592000 And tSecond<31536000 Then'//一年內
    TimeToDiff=DateDiff("m",DateTime,Now())&"個月前"
   End If
   If tSecond>=31536000 Then'//其它
    TimeToDiff=DateDiff("yyyy",DateTime,Now())&"年前"
   End If
  Else
   TimeToDiff="N天前"
  End If
 End Function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.