通过使用波纹管代码我计算2日期之间的差异,这是格式在字符串中 2017-12-19 17:19:35 我做了下面的代码,在谷歌浏览器中工作,但没有在safari中工作。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/a</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:colorActivatedHighlight">@android:color/transparent</item>
<item name="windowActionModeOverlay">true</item>
<item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<item name="android:alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDateStyle</item>
<item name="android:timePickerDialogTheme">@style/AppCompatDateStyle</item>
<item name="colorControlNormal">@color/primaryDark</item>
<item name="colorControlActivated">@color/primary</item>
</style>
<style name="AppCompatDateStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/primary</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/primary</item>
</style>
</resources>
在chrome var lastReportingTime = r.get('updatedate'); // 2017-12-19 17:19:35
var serverCurrentTime = r.get('currtime'); //2018-02-09 03:52:42
var diff = new Date(serverCurrentTime) - new Date(lastReportingTime);
diff /= 60000; //diff converted in minutes.
console.log('diff=',diff);
// for chrome output is diff= 4445024000
// for safari output is diff= NaN
中以分钟为单位返回结果但safari浏览器中的相同代码返回diff
你能解决这个问题吗?
答案 0 :(得分:0)
您可以使用var mymap = L.map('map', {
bounceAtZoomLimits: false
})
获取毫秒,然后减去。
参考和支持表: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf
答案 1 :(得分:0)
日期构造函数的默认实现因浏览器而异。在Chrome中正确解析的某些字符串可能无法在Safari中正确解析。不使用new Date()
,而是使用Ext.Date.parse(theDateString, theExpectedFormat)
。 Docs
答案 2 :(得分:0)
这对我有用
// var lastReportingTime = r.get('updatedate'); // 2017-12-19 17:19:35
// var serverCurrentTime = r.get('currtime'); //2018-02-09 03:52:42
var lastReportingTime = "2017-12-19 17:19:35"
var serverCurrentTime = "2018-02-09 03:52:42"
var diff = new Date(serverCurrentTime.replace(/-/g, "/")) - new Date(lastReportingTime.replace(/-/g, "/"));
diff /= 60000; //diff converted in minutes.
console.log('diff=',diff);
答案 3 :(得分:-1)
使用Date.getTime()进行数学运算: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime