你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。
chrome
firefox
safari
ie8及以上
ST
意法半导体官网
STM32
中文官网
ST
全球论坛
登录/注册
首页
技术问答
话题
资源
创客秀
视频
标签
积分商城
每日签到
UCT时间转北京时间好处理,但日期怎么办?
[复制链接]
yzk376
提问时间:2012-4-18 23:06 /
time=(atol((char*)GPS_Time));
time=(time+80000)%240000; //变换为北京时间
UCT时间转北京时间好处理,但日期怎么办?日期里面的年月日都需要处理,不然日期总是慢8个小时,有没有好的算法?
赞
0
收藏
0
评论
5
分享
发布时间:2012-4-18 23:06
举报
请先
登录
后回复
5个回答
废鱼
回答时间:2012-4-19 10:12:24
a0a.1 0b0c
RE:UCT时间转北京时间好处理,但日期怎么办?
通过处理时间,当UTC时间+时差大于24的时候,日期就加1。
赞
0
评论
回复
支持
反对
TommyWang-28225
回答时间:2012-4-19 20:42:54
a0a.1 0b0c
RE:UCT时间转北京时间好处理,但日期怎么办?
转化到任意时区
static const int days_per_month_in_leapyear [13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const int days_per_month_in_commonyear [13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// ......
// year,month,day中存储当前日期
void UTC2Timezone(long utctime, int n_timezone, int *year, int *month, int *day)
{
int * days_per_month;
utctime /= 10000;
utctime += n_timezone;
days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
if(utctime >= 24)
{
(*day)++;
if( day > days_per_month[*month] )
(*month)++;
if(*month > 12)
(*year)++;
}
else if(utctime < 0)
{
(*day)--;
if(*day < 1)
(*month)--;
if(*month < 1)
(*year)--;
}
*month %= 12;
//days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
day %= days_per_month[month];
}
//......
赞
0
评论
回复
支持
反对
yzk376
回答时间:2012-4-24 07:47:32
a0a.1 0b0c
RE:UCT时间转北京时间好处理,但日期怎么办?
试一试,谢谢!
赞
0
评论
回复
支持
反对
yzk376
回答时间:2012-4-24 10:43:29
a0a.1 0b0c
RE:UCT时间转北京时间好处理,但日期怎么办?
uct时间怎么可能大于等于24呢???
赞
0
评论
回复
支持
反对
yzk376
回答时间:2012-4-24 10:45:26
a0a.1 0b0c
RE:UCT时间转北京时间好处理,但日期怎么办?
uct时间怎么可能小于0呢?
赞
0
评论
回复
支持
反对
所属标签
相似问题
关于
意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号
手机版
快速回复
返回顶部
返回列表
RE:UCT时间转北京时间好处理,但日期怎么办?
RE:UCT时间转北京时间好处理,但日期怎么办?
static const int days_per_month_in_leapyear [13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const int days_per_month_in_commonyear [13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// ......
// year,month,day中存储当前日期
void UTC2Timezone(long utctime, int n_timezone, int *year, int *month, int *day)
{
int * days_per_month;
utctime /= 10000;
utctime += n_timezone;
days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
if(utctime >= 24)
{
(*day)++;
if( day > days_per_month[*month] )
(*month)++;
if(*month > 12)
(*year)++;
}
else if(utctime < 0)
{
(*day)--;
if(*day < 1)
(*month)--;
if(*month < 1)
(*year)--;
}
*month %= 12;
//days_per_month = *year % 4 == 0 ? days_per_month_in_leapyear : days_per_month_in_commonyear ;
day %= days_per_month[month];
}
//......
RE:UCT时间转北京时间好处理,但日期怎么办?
RE:UCT时间转北京时间好处理,但日期怎么办?
RE:UCT时间转北京时间好处理,但日期怎么办?