1970年时间转换

距1970的天数与年月日的转换算法 背景 在日志系统中调用localtime来转换为用户可见的时间(即距1970-01-01的秒数转换为年月日时分秒),会低概率的出现异常。原因是localtime()这个函数是线程不安全的,函数返回一个指向struct tm结构体的指针,这个指针指向一个静态变量。所以在多线程下,会概率性导致踩内存问题。 另外,虽然localtime_r()可以处理这个问题,但是localtime_r()的底层实现上... 阅读详情
+ (NSString *)startTime:(NSString *)startTime endTime:(NSString
*)endTime{
   
NSString *startTimeStr = [[NSString alloc]init
];
   
NSString *endTimeStr = [[NSString alloc]init
];
   
NSInteger startDay = 0
;
   
NSInteger endDay = 0
;
   
if
(startTime) {
       
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[startTime integerValue] / 1000
];
       
NSInteger month = [Utility timeWithDate:date timeType:TimeTypeMouth
];
        startDay  = [
Utility timeWithDate:date timeType:TimeTypeDay
];
       
NSInteger hour = [Utility timeWithDate:date timeType:TimeTypeHour
];
       
NSInteger minute = [Utility timeWithDate:date timeType:TimeTypeMinute
];
        startTimeStr = [
NSString stringWithFormat:@"%02ld月%02ld日 %02ld:%02ld"
,month,startDay,hour,minute];
    }
   
if
(endTime) {
       
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[startTime integerValue] / 1000
];
       
NSInteger month = [Utility timeWithDate:date timeType:TimeTypeMouth
];
        endDay  = [
Utility timeWithDate:date timeType:TimeTypeDay
];
       
NSInteger hour = [Utility timeWithDate:date timeType:TimeTypeHour
];
       
NSInteger minute = [Utility timeWithDate:date timeType:TimeTypeMinute
];
       
if
(startDay == endDay) {
            endTimeStr = [
NSString stringWithFormat:@"%02ld:%02ld"
,hour,minute];
        }
else
{
            endTimeStr = [
NSString stringWithFormat:@"%02ld月%02ld日 %02ld:%02ld"
,month,endDay,hour,minute];
        }
    }
   
NSString *dataTimeStr = [NSString stringWithFormat:@"%@-%@"
,startTimeStr,endTimeStr];
   
return
dataTimeStr;
}

+ (
NSString *)createTime:(NSString
*)time{
   
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[time integerValue] / 1000
];
   
NSInteger year = [Utility timeWithDate:date timeType:TimeTypeYear
];
   
NSInteger month = [Utility timeWithDate:date timeType:TimeTypeMouth
];
   
NSInteger day  = [Utility timeWithDate:date timeType:TimeTypeDay
];
   
NSInteger hour = [Utility timeWithDate:date timeType:TimeTypeHour
];
   
NSInteger minute = [Utility timeWithDate:date timeType:TimeTypeMinute
];
   
NSInteger second = [Utility timeWithDate:date timeType:TimeTypeSecond
];
   
NSString *dateStr = [NSString stringWithFormat:@"%ld-%02ld-%02ld %02ld:%02ld:%02ld"
,year,month,day,hour,minute,second];
   
return
dateStr;
}

+ (
NSInteger)timeWithDate:(NSDate *)date timeType:(TimeType
)timeType {
   
NSCalendar *calendar = [NSCalendar currentCalendar
];
   
NSDateComponents *compt = [calendar components:(NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit) fromDate
:date];
   
NSInteger year = [compt year
];
   
NSInteger month = [compt month
];
   
NSInteger day = [compt day
];
   
NSInteger hour = [compt hour
];
   
NSInteger minute = [compt minute
];
   
NSInteger second = [compt second
];
   
switch
(timeType) {
       
case TimeTypeYear
:
           
return
year;
           
break
;
       
case TimeTypeMouth
:
           
return
month;
           
break
;
       
case TimeTypeDay
:
           
return
day;
           
break
;
       
case TimeTypeHour
:
           
return
hour;
           
break
;
       
case TimeTypeMinute
:
           
return
minute;
           
break
;
       
case TimeTypeSecond
:
           
return
second;
           
break
;
           
       
default:return 1
;
           
break
;
    }
}
时间转换为1970,获取1970年以来的秒数程序 时间转换为1970年以来的秒数工具.exe,用于获取1970年以来的秒数程序 立即下载

相关推荐

SimNow模拟环境实战:用vnpy_ctp连接期货市场的5个关键配置步骤

本文提供了一份详细的量化交易实战指南,重点讲解如何使用vnpy_ctp插件连接SimNow期货模拟环境的5个关键配置步骤。内容涵盖SimNow环境选择、vnpy_ctp核心参数解析、实战连接脚本编写、深度排错技巧以及向实盘迁移的准备,旨在帮助量化交易开发者快速搭建可靠的测试环境,避免常见陷阱。

weixin_29063035的博客 1275

1970年以来的秒转换为具体日期时间

输入:0时区的标准秒数 输出:东8区的具体日期时间 struct TimeDetail { unsigned short day; unsigned short hour; unsigned short minute; unsigned short second; }; struct DateTimeDetail { unsigned short year; unsigned

超频化石鱼的博客 7603

易智联LM401模块学习(一)——初识Lora

Lora

weixin_46046597的博客 1054

时间戳转化成日期时间格式1970年问题

时间戳转化成日期时间格式1970年问题 前端在使用时间戳转化日期经常会遇到一直到都是输出1970的问题, 下面写介绍一种简单的转化方法,适用moment.js 下载 npm install moment --save 在main.js引入 import moment from 'moment' Vue.prototype.$moment = moment; import moment from 'moment' Vue.proto...

weixin_46390461的博客 5863

【Tableau】解决订阅报表PDF中文显示为乱码(方框)问题

一、问题描述 在tableau server网页端报表中文字符能正常显示,但在订阅后发送到邮箱时,以图片格式呈现的内容中中文字符显示为方框。 网页端报表能正常显示中文字符: 邮件中的报表不能正常显示中文字符: 二、问题分析 网页端字符显示情况是由html编码决定的,而tableau生成图片时是通过所部署的服务器的字体文件显示字体。因此可能是由于Linux服务器缺失相关的字体文件导致网页端选择的中文字体在服务器上缺失对应的字体文件导致的。则考虑在服务器引入对应的字体文件。 三、问题解决 1、查看服务器现有

why_not_study的博客 2834

[捷稀 JCG Q30 Pro 刷机说明] 以刷入openwrt24.10为例

摘要: 本文详细介绍了捷稀JCG Q30 Pro路由器刷入OpenWrt 24.10系统的步骤。通过先刷入OpenWrt 23.05过渡固件,再升级Uboot,最后通过TFTP加载工厂镜像完成刷机。关键步骤包括解锁分区、刷写Uboot、进入恢复模式及配置网络。文章还提供了无线设置、Tailscale内网穿透等进阶命令,并附参考文档和固件下载链接。适用于有一定技术基础的玩家,需注意操作风险,严格按流程执行。

贤时间 7148

Unix、UTC、GPS时间戳及转换

Unix、UTC、GPS时间戳及转换

xiaojinger_123的博客 2万+

嵌入式工程师必学(52):储能系统ESS

能量存储系统(ESS,Energystoragesystems)存在于各种各样的尺寸、形状和技术中。储能系统的技术,即基本的储能机制,自然会影响其重要特性,包括成本、安全性、性能、可靠性和寿命。然而,尽管基础技术很重要,但一个成功的储能项目依赖于对该技术的彻底和深思熟虑的实施,以实现项目的目标。成功的实施取决于储能系统的架构和组装情况。系统的体系结构可以决定其性能和可靠性,与它所使用的技术一致,甚至与之无关。

码农17年的博客 1443

python 时间戳与北京时间的相互转换(包括1970年以前)

@BC 1970年之后时间转换方法 时间戳转北京时间 # 时间戳转北京时间 import time time_1 = 1601863976 # 以2020/10/5 10:12:56为例子 time_tuple_1 = time.localtime(time_1) bj_time = time.strftime("%Y/%m/%d %H:%M:%S", time_tuple_1) print("北京时间:", bj_time) 运行结果: 北京时间: 2020/10/05 10:12:56

m0_46650312的博客 6027

PCL——KITTI数据集.bin文件转.pcd并可视化【2025最新版】

kitti数据集中的bin格式点云主要存储的字段为:`x`、`y`、`z`、`intensity`,对应于PCL中的PointXYZI。因此,只需将bin中的属性信息读取出来放入`PointXYZI`即可。本文给出简单易用的实现代码。博客长期更新,本文最近更新时间为:2025年1月11日。

点云侠的博客 3957

6、掌握 CorelDRAW:从基础操作到创意绘图

本文详细介绍了CorelDRAW的基础操作与创意绘图技巧,涵盖软件使用注意事项、常用快捷键、全局与局部设置的区别、Dockers面板的高效使用,并通过绘制带星星图案的球实例,逐步演示了对象创建、编辑、复制、分布优化、元素添加、颜色与特效调整等核心功能,最后讲解了作品的保存与输出方法,帮助用户从入门到进阶掌握CorelDRAW的设计流程。

snow3的博客 122

关于SimpleDateFormat时间转换总是显示1970年的问题

今天遇到了一个奇怪的问题, long time = 1488606363; Date date = new Date(time); java.text.SimpleDateFormat sDateFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Log.e("时间",sDateFormat.for

小李的博客 1万+

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

关于SimpleDateFormat时间转换总是显示1970年的问题(时间戳转日期)

时间戳转时间总是显示1970年,我的时间戳是字符串1527643920 /* * 将时间转换为时间戳 */ public static String dateToStamp(String s) throws ParseException { String res; SimpleDateFormat simpleDateFormat = new SimpleDateFormat...

BoriseLee 7241

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

mysql1970年以后出生的,将1970年之前的日期字符串转换为MySQL中的时间戳

这不是一个很好的标题,所以我深表歉意。由于某种原因(我不是这样做的人,我离题了),我们有一个表结构,其中日期的字段类型为varchar。 (奇)。我们有一些日期,例如:1932-04-01 00:00:00 and 1929-07-04 00:00:00我需要执行一个查询,将这些日期字符串转换为unix时间戳,但是,在mySQL中,如果您转换的日期是1970年之前,它将返回0。有任何想法吗?非常感...

weixin_39904612的博客 1083

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

解决Java时间戳转换成时间之后一直显示1970年的原因

经过查找资料发现,时间需要*1000L之后进行转换,才能变成现在的时间。不管数据库的时间为多少,转换完之后都显示的1970年,下面是源代码。现在看到的时间就是正常的时间了。

暴力扬 4624

Python 时间戳与字符串之间的相互转换(解决1970年之前的时间转换)

Python 时间戳与字符串之间的相互转换(解决1970年之前的时间转换) 1.字符串转换时间戳 字符串转换时间戳 str_time_trans_timestamp 参数 说明 默认 my_time/ 要转换的时间字符串 format_type 传入时间my_time的格式 %Y%m%d timestamp_type 时间戳类型,毫秒或秒 ms(毫秒) import time from datetime import datetime utc_time = datetime.

little duo blog 1436

关于1970年之前的时间要怎么转换成时间戳啊 负数要怎么处理

在这里有的人可能有疑问? 大家都知道java时间戳是从1970年1月1日0时0分0秒开始计算的,那么假如1960年的时间戳应该是多少呢? 下面是答案,负数,通过负数一样可以转化成正常的时间 年月日。 -302688000===========1960-05-30 00:00 ...

u013095264的博客 1万+

Python转换1970年之前的时间戳

Python转换1970年之前的时间戳

小祝的专栏 1162

android 毫秒转日期 1970,Android 时间戳转换成时间总是1970年的问题!!!!!

我当时是这样写的/*** 时间戳转换成时间*/public static String stampToDate(long stamp, String format) {SimpleDateFormat sdf = new SimpleDateFormat(format);//这个是你要转成后的时间的格式Date date = new Date(stamp);String sd = sdf.form...

weixin_36230541的博客 975

关于时间转换总是显示1970年的问题

今天遇到了一个奇怪的问题, long time = 1488606363; Date date = new Date(time); java.text.SimpleDateFormat sDateFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); Log.e("时间",sDateFormat.f

油条的博客 1万+

mysql中1970的时间戳,将1970年之前的日期字符串转换为MySQL中的时间戳

Not a very good title, so my apologies.For some reason, (I wasn't the person who did it, i digress) we have a table structure where the field type for a date is varchar. (odd).We have some dates, such...

weixin_39595430的博客 357

Java时间戳转换踩坑实录:为什么LocalDateTime总是1970年?

本文深入解析Java开发中时间戳转换为LocalDateTime时总是得到1970年的常见问题。核心原因在于混淆了时间戳的单位(秒与毫秒),并错误地使用了Instant.ofEpochMilli方法。文章提供了从问题诊断、正确使用java.time API进行转换,到在Spring Boot与Jackson中优雅配置的完整解决方案,帮助开发者彻底规避这一经典陷阱。

android的专栏 452
上一篇: 什么情况使用 weak 关键字,相比 assign 有什么不同?
下一篇: 禁止 UITextField 的粘贴、复制
develop_csdn_LGQ
博客等级 码龄10年 21粉丝 61原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值