将今天的HH:MM am / pm转换为Bash的纪元

时间:2017-03-01 01:31:24

标签: bash date time epoch

我有两个变量exports.courseFields = function(req, res) { db.Course.find({ where: {id: req.params.PeriodIdF}, attributes: ['id'], include: [{model:db.Room, attributes:['DisplayLabel']}]}) .then(function(courses) { return res.json(courses); }) .catch(function(err) { return res.render('error', { error: err, status: 500 }); }); }; =“上午7:23”和$sunrise =“下午6:10”。我需要将它们转换为今天的时代,如:

$sunset

到目前为止,我唯一想到的是用当前的日期时间来做:

secSunrise=($date ... "$sunrise" ... +"%s")
secSunset=$(date ... "$sunset" ... +"%s")

如何对这个圆圈进行平方并将$ secNow=$(date +"%s") $ echo $secNow 1488331535 12小时格式化变量插入HH:MM am/pm命令?

1 个答案:

答案 0 :(得分:4)

您可以这样使用GNU date

date --date="7:23 am today" +%s
# output => 1488352980

date --date="6:10 pm today" +%s
# output => 1488391800
  • %s打印纪元

来自man date

  

--date=STRING是一种大多数免费格式的人类可读日期字符串   例如"Sun, 29 Feb 2004 16:21:42 -0800""2004-02-29 16:21:42"或   甚至是"next Thursday"。日期字符串可能包含指示的项目   日历日期,时间,时区,星期几,相对时间,   相对日期和数字。空字符串表示开头   当天日期字符串格式比容易复杂   在此处记录,但在信息文档中有详细描述。

相关问题