From d1e516bd9100ecd22f68dde38e37d1b9f57ac36b Mon Sep 17 00:00:00 2001 From: HaoZhang <1315649364@qq.com> Date: Tue, 7 May 2024 09:29:53 +0800 Subject: [PATCH] addtime --- autotv.go | 29 +++++++++++++++++++++++++++++ update_time.txt | 0 2 files changed, 29 insertions(+) create mode 100644 update_time.txt diff --git a/autotv.go b/autotv.go index 0c9205c..dbd1abb 100644 --- a/autotv.go +++ b/autotv.go @@ -32,7 +32,35 @@ func downloadFile(url, filepath string) error { return nil } +func gettime() { + // 获取当前时间 + currentTime := time.Now() + + // 格式化时间为字符串 + timeString := currentTime.Format("2006-01-02 15:04:05") + "\n" + + // 打开文件以追加文本 + filePath := "update_time.txt" + file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("打开文件时出错:", err) + return + } + defer file.Close() + + // 将时间字符串写入文件 + _, err = file.WriteString(timeString) + if err != nil { + fmt.Println("写入文件时出错:", err) + return + } + + fmt.Printf("当前时间已追加到文件 %s\n", filePath) +} + func main() { + gettime() + fileURL := "https://iitzh.com/cn.m3u" filePath := "cn.m3u" @@ -40,4 +68,5 @@ func main() { if err != nil { fmt.Println("下载文件时出错:", err) } + } diff --git a/update_time.txt b/update_time.txt new file mode 100644 index 0000000..e69de29