我是 jQuery 新手,我的所有搜索请求都将我带到处理日期/时间数据类型的方法。但我需要处理一段时间,以分钟为单位。例如,我想将 1708
分钟转换为 “1 天 4 小时”
表达式,忽略分钟。例如,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()
可以获取“现在”时代。但约会方面并没有什么真正擅长的。
我非常喜欢这个库。它运作良好并且可以做所有事情。享受吧!
否则您始终可以手动编写该函数。
关于c# - jQuery 中有一些处理时间段数据类型的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10924052/