2009-03-31 11 views
1

VBScriptの古典的なASP機能のための自然/人間に対する相対的な日付/時刻を持つ人はいますか?これはTwitterのようなものです。古典的なASPの相対日付/時刻

例:

  • 1分未満前に約5分前
  • について
  • 時間前
  • 約3時間前
  • 昨日
  • 水曜日
  • など。

答えて

-1
 

DateAdd("n", -1, Now) 
DateAdd("n", -5, Now) 
DateAdd("h", -1, Now) 
DateAdd("h", -3, Now) 
DateAdd("d", -1, Date) 
DateAdd("d", -1, Date) 
 

水曜日の部分の意味を理解できません。
詳しいことはできますか?

+0

DateDiff関数を使用して、現在の時刻と更新日時を比較します(その場合)。例えば、 – shahkalpesh

+0

。 DateDiff( "n"、dateofupdate、now) – shahkalpesh

3

これは私が使用しているものです。私がこのサイトで使ったジェフの例からちょうどリッピングしたことは間違いありません。

は、はい、はい、私がやった:How can I calculate relative time in C#?

Function RelativeTime(dt) 
    Dim t_SECOND : t_SECOND = 1 
    Dim t_MINUTE : t_MINUTE = 60 * t_SECOND 
    Dim t_HOUR : t_HOUR = 60 * t_MINUTE 
    Dim t_DAY : t_DAY = 24 * t_HOUR 
    Dim t_MONTH : t_MONTH = 30 * t_DAY 

    Dim delta : delta = DateDiff("s", dt, Now) 

    Dim strTime : strTime = "" 
    If (delta < 1 * t_MINUTE) Then 
     If delta = 0 Then 
      strTime = "just now" 
     ElseIf delta = 1 Then 
      strTime = "one second ago" 
     Else 
      strTime = delta & " seconds ago" 
     End If 
    ElseIf (delta < 2 * t_MINUTE) Then 
     strTime = "a minute ago" 
    ElseIf (delta < 50 * t_MINUTE) Then 
     strTime = Max(Round(delta/t_MINUTE), 2) & " minutes ago" 
    ElseIf (delta < 90 * t_MINUTE) Then 
     strTime = "an hour ago" 
    ElseIf (delta < 24 * t_HOUR) Then 
     strTime = Round(delta/t_HOUR) & " hours ago" 
    ElseIf (delta < 48 * t_HOUR) Then 
     strTime = "yesterday" 
    ElseIf (delta < 30 * t_DAY) Then 
    strTime = Round(delta/t_DAY) & " days ago" 
    ElseIf (delta < 12 * t_MONTH) Then 
     Dim months 
     months = Round(delta/t_MONTH) 
     If months <= 1 Then 
      strTime = "one month ago" 
     Else 
      strTime = months & " months ago" 
     End If 
    Else 
     Dim years : years = Round((delta/t_DAY)/365) 
     If years <= 1 Then 
      strTime = "one year ago" 
     Else 
      strTime = years & " years ago" 
     End If 
    End If 
    RelativeTime = strTime 
End Function 
0

ajaxed私はこのような自分自身の関数を書く

'here comes some global helpers... 
public function sayDate(dat, mode, relativNotation) 
    if not isDate(dat) then 
     sayDate = "unknown" 
     exit function 
    end if 
    if relativNotation then 
     diff = dateDiff("s", dat, now()) 
     if diff <= 10 and diff >= 0 then 
      sayDate = "Just now" : exit function 
     elseif diff < 60 and diff >= 0 then 
      sayDate = diff & " seconds ago" : exit function 
     elseif diff = 60 and diff >= 0 then 
      sayDate = diff & " minute ago" : exit function 
     elseif diff <= 1800 and diff >= 0 then 
      sayDate = int(diff/60) & " minutes ago" : exit function 
     elseif diff < 86400 and diff >= 0 then 
      sayDate = plural(int(diff/60/60), "hour", empty) & " ago" 
     else 
      if datevalue(dat) = date() then 
       sayDate = "Today" 
      elseif dateValue(dat) = dateAdd("d", 1, date()) then 
       sayDate = "Tomorrow" 
      elseif dateValue(dat) = dateAdd("d", -1, date()) then 
       sayDate = "Yesterday" 
      end if 
     end if 
    end if 
    if relativNotation and lCase(mode) = "datetime" and isEmpty(sayDate) then 
     diff = dateDiff("d", dat, now()) 
     sayDate = plural(diff, "day", empty) & " ago" 
     exit function 
    end if 

    if isEmpty(sayDate) then 
     sayDate = day(dat) & ". " & monthname(month(dat), true) 
     if year(dat) <> year(now()) then sayDate = sayDate & " " & year(dat) 
    end if 

    if lCase(mode) <> "datetime" then exit function 
    if uBound(split(dat, " ")) <= 0 then exit function 
    'sayDate = sayDate & ", " & str.padLeft(hour(dat), 2, "0") & ":" & str.padLeft(minute(dat), 2, "0") 
end function 

public function plural(val, singularform, pluralform) 
    plural = singularform 
    if val <> 1 then plural = pluralform 
    if isEmpty(plural) then plural = singularform & "s" 
    plural = val & " " & plural 
end function 
0

から取られ、http://asp.web.id/asp-classic-relative-date-function.html

で見つけることができ、それは変換ASPを使用しています日付をunixtimestamp形式に変換し、時間マージンを計算します。この関数を使用して、今後の日付の相対日付を作成することもできます。

関連する問題