jQuery中是否有一些用于处理时间段数据类型的方法

Are there in jQuery some methods for handling period of time data type?

本文关键字:时间段 处理 数据类型 方法 用于 是否 jQuery      更新时间:2023-09-26

我是jQuery的新手,我所有的搜索请求都让我想到了处理日期/时间数据类型的方法。但是我需要处理一段时间,以分钟数表示。例如,我想将1708分钟转换为"1 day and 4 hours"表达式,忽略分钟。例如,C# 中有TimeSpan数据类型,我可以执行以下操作:

public string ConvertMinutes()
        {
            //Number of minutes I have and want to convert
            int n = 1708;
            TimeSpan t = new TimeSpan(0, n, 0);
            string dayshelper = t.Days == 1 ? "day" : "days";
            string hoursHelper = t.Hours == 1 ? "hour" : "hours";
            //The result I want to get
            //For example "4 days and 2 hours"
            string result = string.Empty;
            result += t.Days == 0 ? string.Empty : string.Format("{0} {1}", t.Days, dayshelper);
            result += t.Hours == 0 ? "." : string.Format(" and {0} {1}.", t.Hours, hoursHelper);
            return result;
        }

jQuery中是否有类似的东西?还是我必须自己从分钟数中获取天数和小时数?

jQuery中没有内置的东西。Javascript内置了一些基本功能来处理日期,例如new Date(),它会让你"现在",或者new Date().getTime()会让你得到纪元。但是约会没有什么真正好的。

http://www.datejs.com/

我非常喜欢这个图书馆。它运行良好,无所不包。享受!

否则,您始终可以手动编写函数。

只需在javascript中编写自己的函数即可将分钟转换为字符串。您需要做的就是进行模除以获得整个零件和提醒。继续除以 60 或 24,具体取决于您所在的维度,直到整个零件为 0。

所以 1000 秒我会做

1000/60 = 16 分钟1000 % 60 = 40 秒提醒