两个日期时间字符串之间的时差

时间:2018-02-02 06:10:10

标签: javascript

我有两个日期时间字符串。

# -*- mode: python -*-

block_cipher = None


a = Analysis(['Main.py'],
             pathex=[],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=['C:\\Users\\da\\AppData\\Local\\Programs\\Python\\Python\\Lib\\site-packages\\pandas'],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='win',
          debug=False,
          strip=False,
          upx=True,
          console=True)
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='win')

有人可以建议如何获得两个日期时间之间的时差吗? 如果时差是小时,天,月,则时差应该相同。

1 个答案:

答案 0 :(得分:1)

我希望这会对你有所帮助

var currentTime = '2/2/2018, 11:34:53 AM';
var loggedTime = '2/2/2018, 11:14:46 AM';
var current = new Date(currentTime);
var logged = new Date(loggedTime);
var timeDiff = Math.abs(current.getTime() - logged.getTime());
var diffDays = Math.floor(timeDiff / (1000 * 3600 * 24));
var remainingTime = timeDiff - (diffDays*1000*3600*24);
var hours = Math.floor(remainingTime/(1000*3600));
remainingTime = remainingTime - (hours*1000*3600);
var minutes = Math.floor(remainingTime/(1000*60));
remainingTime = remainingTime - (minutes*1000*60);
var seconds = Math.floor(remainingTime/(1000));
remainingTime = remainingTime - (seconds*1000);
var milliSeconds = remainingTime;
console.log(diffDays+' Days '+hours+ ' Hours '+minutes+' Minutes '+seconds+ ' Seconds '+milliSeconds+' MilliSeconds ');