将秒数转换成年月日时分秒
来源:互联网 发布:安知玉如意txt书包网 编辑:程序博客网 时间:2024/04/27 21:49
// 仅供学习参考,转载请通知作者!
typedef struct
{
uint16_t year;
uint16_t month;
uint16_t date;
uint16_t hour;
uint16_t min;
uint16_t sec;
uint16_t week;
}drive_time,*pdrive_time;
drive_time UTC;
drive_time struct_time = // 初始化时间
{
.year = 1970,
.month = 1,
.date = 1,
.hour = 0,
.min = 0,
.sec = 0,
.week = 0,
};
// second: 秒数,UTC:结构体
int get_UTC(unsigned long second,pdrive_time UTC)// 获取世界标准时间,转换成北京时间需要加上8小时
{
const char Leap_Year_day[2][12] = { {31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31} };
int Leap_Year = 0; // 判断是否闰年
int month_day = 0;//判断当前 月 天数
//------------------初始化检测----------------------------------------------------------------
if( ((struct_time.year) > 9999) || ((struct_time.year) < 1) )
struct_time.year = 1;
Leap_Year = isLeapYear(struct_time.year);
if( ((struct_time.month) > 12) || ((struct_time.month) < 1) )
struct_time.month = 1;
month_day = Leap_Year_day[Leap_Year][struct_time.month-1];
if( ((struct_time.date) > month_day) || ((struct_time.date) < 1) )
struct_time.date = 1;
if( ((struct_time.week) > 7) || ((struct_time.week) < 1) )
struct_time.week = 1;
if( (struct_time.hour) > 23 )
struct_time.hour = 1;
if( (struct_time.min) > 59 )
struct_time.min = 1;
if( (struct_time.sec) > 59 )
struct_time.sec = 1;
//-----------------赋值-------------------------------------------------------------------
UTC->year = struct_time.year;
UTC->month = struct_time.month;
UTC->date = struct_time.date;
UTC->hour = struct_time.hour +(second / 3600 % 24);
UTC->min = struct_time.min+(second / 60 % 60);
UTC->sec = struct_time.sec +(second % 60);
//--------------算出天数----------------------------------------------------------------
uint16_t count_days = second /86400;
if(UTC->sec >=60)
{
UTC->sec = UTC->sec%60;
(UTC->min) ++;
}
if(UTC->min >=60)
{
UTC->min = UTC->min%60;
(UTC->hour) ++;
}
if(UTC->hour >=24)
{
UTC->hour = UTC->hour%24;
(count_days) ++; // 增加天数
}
//---------------计算年月日------------------------------------------------
for(int i = 0 ; i < count_days; i++ )
{
Leap_Year = isLeapYear(UTC->year);
month_day = Leap_Year_day[Leap_Year][(UTC->month)-1];
(UTC->date) ++;
if((UTC->date) > month_day)
{
(UTC->date) = 1;
(UTC->month) ++;
if((UTC->month) > 12)
{
(UTC->month) = 1;
(UTC->year) ++;
if( ( (UTC->year) - (struct_time.year) ) >100)// 设置最大计数100年
return -1;
}
}
}
return 0 ;
}
- 将秒数转换成年月日时分秒
- iOS 把NSTimeInterval 转换成年月日 时分秒
- Calendar将long转换成年月日,时分秒
- Sql 将1970年的秒转换成年月日时分秒
- 将Long类型的时间转换成年月日时分秒
- 年/月/日 时:分:秒 --> 年月日时分秒
- JSON 中的毫秒时间( LONG) ,转换成年月日
- Java 中long型转换成年月日时间
- 日期格式的字符串转换成年月日字符串
- dojo js 字符串日期转换成年-月-日
- Android十位时间戳转【年月】、【月日】、【时分秒】
- 把系统时间的秒数转化成年月日格式
- js转换成时分秒,和日时分秒的格式
- 将秒数转换成天时分秒的格式
- PHP 将秒数转换成时分秒
- 经纬度、时分秒转换
- ms 转换时分秒
- 时分秒转换
- Linux下tomcat的catalina.out文件过大
- ng-src与ng-href
- Python实现监控某个服务,服务崩溃发送邮件报告
- HeadFirst Java 1-18
- Java学习笔记(63)-----------线程进阶
- 将秒数转换成年月日时分秒
- unity2d 实现物体跟随鼠标绕一个点旋转效果
- 华为oj 蛇形矩阵
- bootstrap源码学习之附加导航affix(二)
- Yii2过滤器
- 自定义圆形头像
- C# 对word进行设置目录
- Activity右滑返回效果实现
- 基于AndroidAsync框架搭建android http server