将日期格式化为尽可能短的字符串
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将日期格式化为尽可能短的字符串相关的知识,希望对你有一定的参考价值。
Todays dates are shown as hh:mm, dates from yesterday and earlier as dd mmm.This can be useful, since recent dates are showing more details
<% function FormDate(datum) if datum & "" = "" then FormDate="onbekend" : exit function if datum = "1-1-1900" then FormDate="-nooit-" : exit function hulp=split(replace(datum,"/","-") & ""," ") if UBound(hulp)<1 then FormDate=datum & " !" : exit function tijd=split(hulp(1),":") if UBound(tijd)<2 then FormDate=datum & " !" : exit function dag=split(hulp(0),"-") if UBound(dag)<2 then FormDate=datum & " !" : exit function if instr(datum,"/")>0 then hulp=dag(1) : dag(1)=dag(0) : dag(0)=hulp if len(dag(1))=1 then dag(1)="0" & dag(1) dag(1)=mid("XXJanFebMrtAprMeiJunJulAugSepOktNovDec",dag(1)*3,3) if len(tijd(0))=1 then tijd(0)="0" & tijd(0) if len(tijd(1))=1 then tijd(1)="0" & tijd(1) if len(dag(0))=1 then dag(0)="0" & dag(0) if datum>=date() then FormDate=tijd(0) & ":" & tijd(1) & "u" else if year(datum)=year(date()) then FormDate=dag(0) & "-" & dag(1) & " " ' & tijd(0) & ":" & tijd(1) & "u" else FormDate=dag(0) & "-" & dag(1) & "-" & dag(2) & " " ' & tijd(0) & ":" & tijd(1) & "u" end if end if end function %>
以上是关于将日期格式化为尽可能短的字符串的主要内容,如果未能解决你的问题,请参考以下文章
C# DateTime 将日期字符串格式化为带时区的日期格式