- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章ios中getTime()的兼容性实例代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
时间格式为:2017-12-12 12:00:00在苹果上获取时间戳有兼容性问题 。
需要转换成2017/12/12 12:00:00 才可以正确获取到时间戳 。
1
2
3
4
5
6
7
8
9
10
|
let u = navigator.userAgent;
//判断浏览器型号
let isAndroid = u.indexOf(
'Android'
) > -1 || u.indexOf(
'Adr'
) > -1;
//android终端
let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
//ios终端
if
(isiOS){
let time =
new
Date((v[0].createTime).replace(/-/g,
'/'
)).getTime();
this
.timeago=
this
.getDateDiff(time);
}
else
{
let time =
new
Date(v[0].createTime).getTime();
this
.timeago=
this
.getDateDiff(time);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
判断时间过去了多久
getDateDiff(dateTimeStamp){
let result;
let minute = 1000 * 60;
let hour = minute * 60;
let day = hour * 24;
let halfamonth = day * 15;
let month = day * 30;
let now =
new
Date().getTime();
let diffValue = now - dateTimeStamp;
if
(diffValue < 0){
return
;
}
let monthC =diffValue/month;
let weekC =diffValue/(7*day);
let dayC =diffValue/day;
let hourC =diffValue/hour;
let minC =diffValue/minute;
if
(monthC>=1){
if
(monthC<=12)
result=
""
+ parseInt(monthC) +
"月前"
;
else
{
result=
""
+ parseInt(monthC/12) +
"年前"
;
}
}
else
if
(weekC>=1){
result=
""
+ parseInt(weekC) +
"周前"
;
}
else
if
(dayC>=1){
result=
""
+ parseInt(dayC) +
"天前"
;
}
else
if
(hourC>=1){
result=
""
+ parseInt(hourC) +
"小时前"
;
}
else
if
(minC>=1){
result=
""
+ parseInt(minC) +
"分钟前"
;
}
else
{
result=
"刚刚"
;
}
return
result;
},
|
到此这篇关于ios中getTime()的兼容性实例代码的文章就介绍到这了,更多相关getTime()的兼容性内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
原文链接:https://juejin.im/post/5b42cbaef265da0fa009fd31 。
最后此篇关于ios中getTime()的兼容性实例代码的文章就讲到这里了,如果你想了解更多关于ios中getTime()的兼容性实例代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
假设我有一个日历对象 c。这行的结果是什么: c.getTimeInMilis(); 和 c.getTime().getTime(); 最佳答案 表面上它们是相同的。 但我更喜欢第一个,因为它不会(明
虚拟机的运行时间是如何计算的,而系统时间是如何计算的?我知道我可以通过调用来获取 AVM 的当前运行时间: getTimer(); 我可以通过执行以下操作来获取当前的 unix 系统时间: new D
对于负毫秒值,Java 和 JavaScript 似乎给出了不同的结果。 Java: System.out.println(new Date(-12220000000000L)); Wed Sep 2
我目前正在验证生成的 Excel 工作表是否包含正确呈现的“时间戳”,其日期和时间部分位于不同的单元格中,并且其格式已根据语言环境进行了调整。 我的测试用例失败了,因为当我从字符串中读回 Excel
这个问题已经有答案了: Difference between Date(dateString) and new Date(dateString) (10 个回答) 已关闭 3 年前。 我一直在处理日期
是否可以创建一个 jQuery 函数来获取当前日期和时间?我一直在查看文档,但到目前为止还没有找到任何东西...... 最佳答案 @nickf 是正确的。然而,更准确地说: // if you try
当我尝试设置每天的倒计时时,遇到此错误。这是我的脚本: var date; var display = document.getElementById('time'); $(document).rea
所以我在比较两个日期时遇到问题。今天存储为 2016-04-17,日期存储为相同的值,只是日期后面有分钟和秒。即使我已将今天存储为日期,today.getTime() 似乎也不起作用。感谢您的帮助。
我有下面的代码: Date now = CalendarUtils.getCalendar(getDefaultTimeZone()) .getTime(); Cale
这个问题已经有答案了: Java Calendar adds a random number of milliseconds? (4 个回答) 已关闭 5 年前。 我想知道为什么我总是得到这个日期之间
我遗漏了一些东西,但我在网上找不到任何提示。当我使用 Javascript 的 getTime() 函数时,它似乎不是从 1970, 01, 01, 0, 0, 0, 0 即 1970 年午夜算起,而
谁能给我解释一下这个例子,请: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_gettime function myFuncti
我对 HTML 和 Javascript 相当陌生,所以我正在尝试制作一个小的增量游戏作为练习。这是我试图用来计算自动增益/秒的代码,以及在选项卡未处于焦点和 setInterval 停止运行时进行相
我正在用 html 做一个小测验,有 10 个问题,每个问题都在一个单独的 html 页面中。当用户按下 index.html 中的开始按钮时,我执行以下操作: var s = new Date();
我知道有很多与此相关的问题,但我找不到有帮助的信息...我只需要在我的脚本中解决这个问题,有人可以帮助我吗? function dateValidation() { this.validateDate
我在尝试设置一个计数器来计算填写特定表格所花费的总时间时遇到此错误。尝试了以下操作, //script var timeStart; var timeStop; $(document).load(fu
我在我的系统中使用时间戳。一切正常,但我发现将 [12:2:2] 作为时间戳很烦人。因为您不知道它是 20 还是 2。 我又累又病,开始以为是编译器的问题。 java.util.Date da
有没有办法在不获取毫秒时间的情况下使用 Date().getTime() 函数?如果没有,是否有 .getTime() 的替代品,它只会给我以分钟为单位的精度? 我也不确定如何从日期对象中去除毫秒数。
我想传递日期对象方法,例如 getMinutes()、getTime() 或 getDay() 作为回调功能如: formatDate = (date, callback) => { date
我使用 javascript getTime() 函数将出生日期存储在 mongodb 中。现在我想在我的数据库中查询所有 20 到 30 岁之间的人。我如何在服务器上执行此操作? { birth_d
我是一名优秀的程序员,十分优秀!