UTC日期转时间戳
网上的方法用mktime来转换日期到时间戳,会被当前环境的时区影响,现在这么做,用UTC的日期转时间戳这样要转换各地的时区也简单
unsigned long
utcMktime(const unsigned int year0, const unsigned int mon0,
const unsigned int day, const unsigned int hour,
const unsigned int min, const unsigned int sec)
{
unsigned int mon = mon0, year = year0;
/* 1..12 -> 11,12,1..10 */
if ( >= (int) (mon -= )) {
mon += ; /* Puts Feb last since it has leap day */
year -= ;
} return ((((unsigned long)
(year/ - year/ + year/ + *mon/ + day) +
year* -
)* + hour /* now have hours */
)* + min /* now have minutes */
)* + sec; /* finally seconds */
}
使用很简单这样就行了
//UTC时间的2019/4/25 13:24:17即北京时间2019/4/25 21:24:17
printf("---%d---\n",(int)utcMktime(,,,,,));
UTC日期转时间戳的更多相关文章
- python中时间、日期、时间戳的转换
1.简介 在编写代码时,往往涉及时间.日期.时间戳的相互转换. 2.示例 # 引入模块 import time, datetime 2.1 str类型的日期转换为时间戳 # 字符类型的时间 tss1 ...
- Python 日期和时间戳的转换
Python 日期和时间戳的转换 1. Python中处理时间的模块 Python中处理时间的模块有time.datetime和calendar. 在Python中表示时间的方式: 时间戳:10位整数 ...
- plsql programming 10 日期和时间戳
年 月 日 时 分 秒 时区 用小时表示的相对于 UTC 的时差 用分钟表示的相对于 UTC 的时差 date 存储日期和时间, 不带时区, 精确到秒 timestamp 存储日期和时间, 不带时区, ...
- java 日期转时间戳,时间戳转为日期
package date; import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Dat ...
- MySQL 日期和时间戳互相转换
① 时间戳转换成日期 FROM_UNIXTIME 例如: 数据表中 invest_time 存储的是时间戳,如 1429063399 使用 FROM_UNIXTIME 可以把时间戳转换为日期: sel ...
- 前端(js/jquery) 日期和时间戳的转换
一.JavaScript中获取当前时间的时间戳 方法一: var timestamp=Date.parse(new Date()); ====>结果是:1451441086000 注:这种方式精 ...
- php日期转时间戳,指定日期转换成时间戳
写过PHP+MySQL的程序员都知道有时间差,UNIX时间戳和格式化日期是我们常打交道的两个时间表示形式,Unix时间戳存储.处理方便,但 是不直观,格式化日期直观,但是处理起来不如Unix时间戳那么 ...
- Python3 日期与时间戳相互转换
开发中经常会对时间格式处理,对于时间数据,比如2019-02-28 10:23:29,有时需要日期与时间戳进行相互转换,在Python3中主要用到time模块,相关的函数如下: 其中unix_time ...
- mysql语句将日期转换为时间戳的方法
mysql将日期转换为时间戳更新数据库: update test set creattime=UNIX_TIMESTAMP('2018-04-19') 替换字段为当前日期: update test s ...
随机推荐
- 部署master节点组件
部署master节点组件 master节点的组件有:kube-apiserver,kube-scheduler,kube-controller-manager 大致安装步骤如下: # mkdir -p ...
- reduce方法的封装使用
reduce()方法 语法: arr.reduce( function(previousValue, item, index, arr) { }, initialValue) previousValu ...
- git ignore 如何忽略已经提交的文件修改
git ignore git ignore的作用很简单,本地仓库忽略一些文件的修改. ignore的规格可以按文件匹配,按后缀匹配或者按文件夹匹配. 如果在项目开发过程中,需要忽略某一个文件已经提交的 ...
- Linux分布式消息队列RocketMQ部署与监控--双Master
环境准备:CentOS_6.5_x64 IP: 192.168.0.249 dbTest249 Master1 IP: 192.168.0.251 webTest251 Master2 下载 ali ...
- idea中 参数没有描述报错 @param XX tag description is missing错误,去除黄色警告
最近在使用idea开发工具,在方法备注中参数没有描述报错就会报一些黄色警告: @param XX tag description is missing,下面展示去除黄色警告的方法 File--sett ...
- Delphi Timer组件
- 韦东山嵌入式Linux学习笔记08--中断体系结构
中断是什么? 举个栗子, 系统怎么知道你什么时候插入鼠标这个设备? 可以有两种处理方式: 1. 查询方式: 轮询去检测是否有设备插入; 2. 中断的方式 当鼠标插入这个事件发生时, 置位某个寄存器,告 ...
- Could not determine which “make” command to run. Check the “make” step in the build configuration
环境: QT5.10 VisualStudio2015 错误1: Could not determine which “make” command to run. Check the “make” s ...
- jQuery获取兄弟标签的文本
// 一个div里面有一个span标签和多个button标签,每个button标签都有id,span标签没有id,通过点击其中一个button标签,来获取到span标签的text function ( ...
- 第三章 指令-- 30 指令-使用钩子函数的第二个binding参数拿到传递的值
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...