python - Get epoch time and replace old value
问题描述
I have a Python script which connects to discord for a 'custom' rich presence. Every time I want to use it, I have to edit the script to enter in the current Epoch time so the counter on Discord starts from when I run the script. I was wondering if there was a way to automate this, having the script get the current time value and replace the old value which was there on run. May not be possible.
解决方案
from datetime import datetime
now = datetime.utcnow()
epoch_time = int((now - datetime(1970, 1, 1)).total_seconds())
这应该收集您当前的纪元时间。
推荐阅读
- django-rest-framework - 使用与 faker 集成的 factory boy 从名称列表中进行选择
- json - 将请求内容 json 解析为 Laravel 中的对象
- linux - 如何在 Linux 系统上启动内存中的应用程序
- reactjs - 在反应原生中保存状态
- c# - 属性或索引器不能分配给它在 C# 中是只读的
- discord.js - 每台服务器运行一个 Discord bot 实例,因此 bot 不会在每台服务器上打开
- android - Kotlin 程序在将 clickListener 设置为在膨胀的 XML 中定义的按钮时抛出 nullPointerException,不知道该去哪里
- angular - 如何使用 RxJS 将我的二维数组重新映射到目标模式?
- r - 如何解决:R CMD检查报告警告和错误
- arrays - 如何使用 matplotlib 为二维数组中的所有(仅 4 种)类型的值绘制图例?