将日期格式化为尽可能短的字符串

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
  1. <%
  2. function FormDate(datum)
  3. if datum & "" = "" then FormDate="onbekend" : exit function
  4. if datum = "1-1-1900" then FormDate="-nooit-" : exit function
  5. hulp=split(replace(datum,"/","-") & ""," ")
  6. if UBound(hulp)<1 then FormDate=datum & " !" : exit function
  7. tijd=split(hulp(1),":")
  8. if UBound(tijd)<2 then FormDate=datum & " !" : exit function
  9. dag=split(hulp(0),"-")
  10. if UBound(dag)<2 then FormDate=datum & " !" : exit function
  11. if instr(datum,"/")>0 then hulp=dag(1) : dag(1)=dag(0) : dag(0)=hulp
  12. if len(dag(1))=1 then dag(1)="0" & dag(1)
  13. dag(1)=mid("XXJanFebMrtAprMeiJunJulAugSepOktNovDec",dag(1)*3,3)
  14. if len(tijd(0))=1 then tijd(0)="0" & tijd(0)
  15. if len(tijd(1))=1 then tijd(1)="0" & tijd(1)
  16. if len(dag(0))=1 then dag(0)="0" & dag(0)
  17. if datum>=date() then
  18. FormDate=tijd(0) & ":" & tijd(1) & "u"
  19. else
  20. if year(datum)=year(date()) then
  21. FormDate=dag(0) & "-" & dag(1) & " " ' & tijd(0) & ":" & tijd(1) & "u"
  22. else
  23. FormDate=dag(0) & "-" & dag(1) & "-" & dag(2) & " " ' & tijd(0) & ":" & tijd(1) & "u"
  24. end if
  25. end if
  26. end function
  27. %>

以上是关于将日期格式化为尽可能短的字符串的主要内容,如果未能解决你的问题,请参考以下文章

将字符串格式化为日期时间

Swift:将开始和结束日期格式化为单个字符串

当我将字符串格式化为日期时出现错误的日期

C# DateTime 将日期字符串格式化为带时区的日期格式

Excel/CSV - 如何停止 excel 自动将字符串格式化为日期

如何使用 Freemarker 将 CRM“仅日期”字段格式化为字符串?