最近在做移动端项目 ,有个设置开始时间和结束时间,然后倒计时 这个活动还有几天。在安卓上能正确转换时间,但在iOS上不能显示,为NaN-NaN1-NaN  Invalid Date,

就好比new Date('2017-09-18 14:58:32').getTime();      /  /在ios上死活拿不到时间戳显示NaN

我也查阅了相关的资料,后来发现:

原来是低版本的Safari解释new Date('2013-10-21')这个对象不一样,在IOS5中的Safari不支持这种写法,

而它支持的写法为new Date('2013','10','21'),这样写就能解决"Invalid Date"的问题

所以想要正确显示时间在iOS上,应该这么写

new Date("2010-03-15 10:30:00".replace(/-/g,'/')).getTime();   解决了问题!!

然后附上 时间相差的倒计时代码

//倒计时
setInterval( function()
{
//设置开始时间
var startTime = ($dp.$( 'time1' ).value.replace( /-/g, '/' ));
// 当前时间
var nowTime = new Date().getTime();
if( new Date( startTime ).getTime() - nowTime > 0 )
{
$( "#timeText" ).removeClass( "none" ).html( "未开始" );
$( ".downTime ul" ).addClass( "none" );
}
else
{
$( ".downTime ul" ).removeClass( "none" );
$( "#timeText" ).addClass( "none" );
var endTime = new Date( $dp.$( 'time2' ).value.replace( /-/g, '/' ) );
// 相差的时间
var t = endTime.getTime() - nowTime;
if( t <= 0 )
{
$( ".downTime ul" ).addClass( "none" );
$( ".downTime #timeText" ).removeClass( "none" ).html( "已结束" );
return false;
}
var d = Math.floor( t / 1000 / 60 / 60 / 24 ); var h = Math.floor( t / 1000 / 60 / 60 % 24 );
var i = Math.floor( t / 1000 / 60 % 60 );
var s = Math.floor( t / 1000 % 60 );
$( "#d" ).html( d );
$( "#h" ).html( h );
$( "#i" ).html( i );
$( "#s" ).html( s );
} }, 100 );

js倒计时功能中newData().getTime()在iOS下会报错,显示 nan的更多相关文章

  1. javascript的倒计时功能中newData().getTime()在iOS下会报错问题解决

    javascript的倒计时功能中newData().getTime()在iOS下会报错问题解决 在做移动端时间转化为时间戳时,遇到了一个问题,安卓手机上访问时,能拿到时间戳,从而正确转换时间,而在i ...

  2. 【转】 IOS开发xcode报错之has been modified since the precompiled header was built

    本文转载自  IOS开发xcode报错之has been modified since the precompiled header was built 其实我是升级xcode到4.6.3的时候遇到的 ...

  3. IOS开发 xcode报错之has been modified since the precompiled header was built

    转载的文章  很实用 IOS开发xcode报错之has been modified since the precompiled header was built 今天做百度地图的时候第一次发现下面错误 ...

  4. php中读取中文文件夹及文件报错

    php读取时出现中文乱码 一般php输出中出现中文乱码我们可用 header ('content:text/html;charset="utf-8"'); php中读取中文文件夹及 ...

  5. IDEA中写MyBatis的xml配置文件编译报错的坑

    IDEA中写MyBatis的xml配置文件编译报错的坑 说明:用IDEA编译工具在项目中使用Mybatis框架,编写mybatis-config.xml和Mapper.xml配置文件时,编译项目出现错 ...

  6. vue 中使用 watch 出现了如下的报错

    vue 中使用 watch 出现了如下的报错 报错: Method "watch" has type "object" in the component def ...

  7. js 倒计时功能,获取当前时间的年月日,时分秒

    一.实现当前时间到指定截止时间的倒计时功能 <html> <head> <title>TEST</title> </head> <bo ...

  8. 如何在webapp中做出原生的ios下拉菜单效果

    github:https://github.com/zhoushengmufc/iosselect webapp模仿ios下拉菜单 html下拉菜单select在安卓和IOS下表现不一样,iossel ...

  9. iOS开发编译报错、常见问题(实时更新)

    一.报错与警报 1.错误代码:No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCH ...

随机推荐

  1. maven 安装jar包命令

    以 spring-context-support-3.1.0.RELEASE.jar 为例,在 @3图中已经给出这个 jar 包的 groupId,artifactId,version信息,手动安装的 ...

  2. WPF Knowledge Points - 默认视图(DefaultView),CollectionSourceView,CollectionView的区别

    这些天一直在做一些关于Treeview的事情,想写出来一些用法和心得.说到集合对象的显示和表现,CollectionSourceView和CollectionView有着至关重要的作用,所以在写Tre ...

  3. Linux_OpenSSH远程连接

    目录 目录 SSH server SSH服务属性 SSH协议执行原理 SSH连接方式 ssh Commands scp commands sftp commands SSH在生产环境中的使用 系统间备 ...

  4. linux 安装 sudo

    1.安装sudo# apt-get install sudo2.修改 /etc/sudoers 文件属性为可写# chmod +w /etc/sudoers3.编辑 /etc/sudoers ,添加如 ...

  5. spring几种获取 HttpServletRequest 对象的方式

    以下的 request 实例都编号了,一共 4 种 方式 1.@Autowired 方式2.public void Test(HttpServletRequest request1, HttpServ ...

  6. elementUI 分页bug解决

    在使用elementui的分页组件时,我发现当对表格数据进行删除时,而且是删除到该页最后一条数据时,当前页面currentPage并不能自动减1,也就是说,当前页currentPage只有你点击页码时 ...

  7. Bean与Map的转换 和 Map与Bean的转换

    package com.JUtils.beanConvert; import java.beans.BeanInfo; import java.beans.IntrospectionException ...

  8. uwsgi + nginx 部署python项目(一)

    uWSGI uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI / uws ...

  9. JAVA基础面向对象分析

    面向对象内存的分析: 一:内存的分类 1:栈(tack) 2:堆(heop) 3: 静态区 4:代码区 二:引用数据类型内存特点 三:引用数据类型传值的特点 四:引用数据类型在作为参数时的特点 面向对 ...

  10. Kubernetes服务部署解决方案

    学习了K8S的基础知识,我们的目的就是解决我们服务的迁移,那么接下去通过几个案例来感受一下K8s部署带来的便捷与效率. 环境准备: 3个节点,然后我这边也安装了 Ingress. 部署wordpres ...