将VB函数转换为Javascript

时间:2011-02-23 14:00:52

标签: javascript vb.net

那里有任何可以为我转换的VB / Javascript专家吗?

Protected Function RelativeTime(ByVal dtTime As DateTime) As String
        Dim timeDiff As TimeSpan = DateTime.Now.ToUniversalTime().Subtract(dtTime)

        If timeDiff.TotalMinutes < 1 Then
            Return "less than a minute ago."
        ElseIf timeDiff.TotalMinutes < 2 Then
            Return "about one minute ago"
        ElseIf timeDiff.TotalMinutes < 60 Then
            Return String.Format("about {0:N0} minutes ago", timeDiff.TotalMinutes)
        ElseIf timeDiff.TotalHours < 2 Then
            Return "about an hour ago"
        ElseIf timeDiff.TotalHours < 12 Then
            Return String.Format("about {0:N0} hours ago", timeDiff.TotalHours)
        ElseIf timeDiff.TotalDays < 365 Then
            Return dtTime.ToString("MMM d")
        Else
            Return dtTime.ToString("MMM d, yyyy")
        End If
    End Function

1 个答案:

答案 0 :(得分:1)

有很多答案可以解决这个问题。只需搜索“javascript time ago”。