GitHub Actions UTC 时间转换 All In One
GitHub Actions UTC 时间转换 All In One
UTC
http://www.timebie.com/cn/stduniversal.php
UTC 时间
世界的每个地区都有自己的本地时间
,在 Internet 及无线电通信时,时间的统一非常重要!
整个地球分为二十四
时区,每个时区都有自己的本地时间。
在国际无线电通信
中,为统一而普遍使用一个标准时间
,称为通用协调时
(UTC, Universal Time Coordinated
)。
UTC 与格林威治时间
平均时 (GMT, Greenwich Mean Time
)一样,都与英国
伦敦的本地时相同。
UTC
与 GMT
含义完全相同。
格林尼治时间 0
http://zh.thetimenow.com/utc/coordinated_universal_time
北京时间
+8
const changeUTCTimeToChinaTime = () => {
const timestamp = Date.now();
// GMT+0800 (China Standard Time)
// 28800000 毫秒 = 60 分/时 * 8 时 * 60 秒/分 * 1000 毫秒/秒
return new Date(timestamp + 60 * 8 * 60 * 1000)
}
UTC 时间转换
00:08 => 09:03:55/ 09:04:32 / 09:01:06
❌
23:00 => 07:09:31
23:59 => 08:00:00 ???
⚠️ GitHub Actions
定时任务
,UTC 时间执行不一定准确,存在延迟
bug, 设置的时间不是实际执行的时间!
cron 定时任务
schedule:
- cron: '0 8 * * *'
# UTC 时间每天 8 点,自动执行一次定时任务 ✅ cron / crontab
js 温度单位转换 / js temperature converter
摄氏度
℃
& 华氏℉
32 华氏
温标 === 0 摄氏
温标
转换公式 Formula
(32°F − 32) × 5/9 = 0°C
function temperatureConverter(ft) {
var fv = parseFloat(ft);
return (fv - 32) / 1.8;
}
Convert from Fahrenheit to Celsius
从华氏度转换为摄氏度
℃=(℉-32)/1.8
convert from Fahrenheit to Kelvin
转换 华氏度 为 开尔文
K=((℉-32)/1.8)+273.15
demos
bug
OK
使用 GitHub Actions 的 corn 定时任务服务,每天自动发送一封天气预报 email
- Linux shell script
weather.sh
#!/usr/bin/env bash
# shebang 指定脚本的运行环境
# 设置 shell 中局部变量的值
set -eux
# 设置 env
LANGUAGE="zh-CN"
CITY=Shanghai
UNIT=m
# m 表示 °C
# u 表示 °F (default)
# UNIT=u
UA="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4343.0 Safari/537.36"
# 文档见 wttr.in
# cURL 发送 GET 请求, 参数 -H header 设置请求头, -o output 输出文件 html
curl \
-H "Accept-Language: $LANGUAGE" \
-H "User-Agent: $UA" \
-o result.html \
https://wttr.in/$CITY?$UNIT
# update, HTTPS ✅
# wttr.in/$CITY?$UNIT
# old, HTTP ❌
# wttr.in/$CITY?format=4\&$UNIT
# refs
# https://github.com/xgqfrms/weather-email-action/issues/3
https://github.com/xgqfrms/weather-email-action/blob/main/weather.sh
/Users/xgqfrms-mbp/Documents/GitHub/gitHub-secrets-all-in-one/weather.sh
- workflow
weather-email-bot.yml
# This is a basic workflow to help you get started with Actions
name: Weather_Email_Bot
# Controls when the action will run.
on:
# Triggers the workflow on push events but only for the main branch
push:
branches: [ main ]
schedule:
- cron: '0 8 * * *'
# UTC 时间每天 8 点,自动执行一次定时任务 ✅ cron / crontab
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
hello-job:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
# weather job
weather-email-bot:
runs-on: ubuntu-latest
steps:
- name: 'Checkout codes'
uses: actions/checkout@v1
# 自动获取天气信息
- name: 'Get Weather'
run: bash ./weather.sh
# 自定义 env, $GITHUB_ENV => ${{env.REPORT_DATE}}
- name: 'Get Date'
run: echo "REPORT_DATE=$(TZ=':Asia/Shanghai' date '+%Y-%m-%d %T')" >> $GITHUB_ENV
# 自动发送邮件
- name: 'Send mail'
uses: dawidd6/action-send-mail@master
with:
server_address: smtp.163.com
server_port: 465
# username: ${{ secrets.MAIL_USERNAME }}
# password: ${{ secrets.MAIL_PASSWORD }}
username: ${{ secrets.MAILUSERNAME }}
password: ${{ secrets.MAILPASSWORD }}
# fix secrets name bug ✅
subject: Shanghai Weather Report (${{env.REPORT_DATE}})
html_body: file://result.html
to: ${{ secrets.MAILTO }}
from: GitHub Actions
# content_type: text/html
# test
- name: 'Print Name bug'
run: |
echo "secrets.MAILUSERNAME = " ${{ secrets.MAILUSERNAME }}
- name: 'Print GITHUB_ENV env ✅'
run: |
echo "❓ env.REPORT_DATE = " ${{env.REPORT_DATE}}
https://github.com/xgqfrms/weather-email-action/blob/main/.github/workflows/weather-email-bot.yml
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
cron
/ crontab
Tools
issues
https://github.com/xgqfrms/weather-email-action/issues/3
https://github.com/chubin/wttr.in/issues/553
https://github.com/chubin/wttr.in/issues/912
refs
https://www.cnblogs.com/xgqfrms/p/17682121.html
https://www.cnblogs.com/xgqfrms/p/17683697.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14097254.html
未经授权禁止转载,违者必究!