在bash中检测夏令时 [英] Detect daylight saving time in bash

查看:71
本文介绍了在bash中检测夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测我是冬季还是夏季。我当前的方法是:

I want to detect if I'm in winter or summer time. My current approach is:

if date +%Z | grep -e CET -e EST; then
  # I'm in winter time
else
  # I'm in summer time
fi

有明显的缺点,因为您必须知道所有时区名称。

which have obvious drawback as you have to know all the timezone names.

推荐答案

抢险的人:

if perl -e 'exit ((localtime)[8])' ; then
    echo winter
else
    echo summer
fi

这篇关于在bash中检测夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆