Python比较文本文件的纪元时间

时间:2017-01-24 10:51:36

标签: python datetime

如何将文本文件abc.txt中的纪元时间与下面的内容进行比较?

createGizmo (center, euler, size, radius, color, range, axis) {

    var material = new GizmoMaterial({
      color: color
    })

    var subMaterial = new GizmoMaterial({
      color: color
    })

    var torusGizmo = new THREE.Mesh(
      new THREE.TorusGeometry(
        radius, size, 64, 64, range),
      material)

    var subTorus = new THREE.Mesh(
      new THREE.TorusGeometry(
        radius, size, 64, 64, 2 * Math.PI),
      subMaterial)

    subTorus.material.highlight(true)

    var transform = new THREE.Matrix4()

    var q = new THREE.Quaternion()

    q.setFromEuler(euler)

    var s = new THREE.Vector3(1, 1, 1)

    transform.compose(center, q, s)

    torusGizmo.applyMatrix(transform)

    subTorus.applyMatrix(transform)

    var plane = this.createBox(
      this.size * 100,
      this.size * 100,
      0.01)

    plane.applyMatrix(transform)

    subTorus.visible = false

    //this.viewer.impl.addOverlay(
    //  this.overlayScene, torusGizmo)
    //
    //this.viewer.impl.addOverlay(
    //  this.overlayScene, subTorus)

    this.viewer.impl.sceneAfter.add(torusGizmo)
    this.viewer.impl.sceneAfter.add(subTorus)

    torusGizmo.subGizmo = subTorus
    torusGizmo.plane = plane
    torusGizmo.axis = axis

    return torusGizmo
  }

条件:如果当前时间超过5分钟5分钟,请打印" 0",否则打印" 1"

1 个答案:

答案 0 :(得分:0)

你可以使用减法。

获取当前纪元,从文件中减去纪元,并检查结果是否超过300秒。

import time

with open('abc.txt') as f:
    epoch = float(next(f).split(':')[1])

if time.time() - epoch > 300:
    print(0)
else:
    print(1)

或更简洁:

print(0 if time.time() - epoch > 300 else 1)