zl程序教程

您现在的位置是:首页 >  系统

当前栏目

便利的获取系统的时分秒

系统 获取 便利 时分秒
2023-09-14 08:57:16 时间

便利的获取系统的时分秒

源码如下:

GlobalNormalTime.h 与 GlobalNormalTime.m

//

// GlobalNormalTime.h

// YouXianMingClock

// Created by YouXianMing on 14-10-12.

// Copyright (c) 2014年 YouXianMing. All rights reserved.

#import Foundation/Foundation.h 

@interface GlobalNormalTime : NSObject

 * 当前时间的数组

 * @return 返回有3个元素的数组(0处为小时,1处为分钟,2处为秒)

+ (NSArray *)currentTime;

 * 当前秒

 * @return 当前秒

+ (float)currentSecond;

 * 当前分钟

 * @return 当前分钟

+ (float)currentMinute;

 * 当前小时

 * @return 当前小时

+ (float)currentHour;

@end


//

// GlobalNormalTime.m

// YouXianMingClock

// Created by YouXianMing on 14-10-12.

// Copyright (c) 2014年 YouXianMing. All rights reserved.

#import "GlobalNormalTime.h"

static NSDateFormatter* _DMLogDateFormatter = nil;

@implementation GlobalNormalTime

+ (void)initialize

 if (self == [GlobalNormalTime class]) {

 // 日期格式

 _DMLogDateFormatter = [[NSDateFormatter alloc] init];

 [_DMLogDateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];

 [_DMLogDateFormatter setDateFormat:@"HH:mm:ss"];

+ (NSArray *)currentTime

 NSString *timerNow = [_DMLogDateFormatter stringFromDate:[NSDate date]];

 NSArray *timeArray = [timerNow componentsSeparatedByString:@":"];

 return timeArray;

+ (float)currentSecond

 NSString *timerNow = [_DMLogDateFormatter stringFromDate:[NSDate date]];

 NSArray *timeArray = [timerNow componentsSeparatedByString:@":"];

 // 获取到时间

 float sec = [timeArray[2] intValue];

 return sec;

+ (float)currentMinute

 NSString *timerNow = [_DMLogDateFormatter stringFromDate:[NSDate date]];

 NSArray *timeArray = [timerNow componentsSeparatedByString:@":"];

 // 获取到时间

 float min = [timeArray[1] intValue];

 return min;

+ (float)currentHour

 NSString *timerNow = [_DMLogDateFormatter stringFromDate:[NSDate date]];

 NSArray *timeArray = [timerNow componentsSeparatedByString:@":"];

 // 获取到时间

 float hour = [timeArray[0] intValue];

 return hour;

@end

以下提供简易分析,使用非常简单,试一下就知道了


C++ 日期和时间编程总结 在 C++11 之前,C++ 编程只能使用 C-style 日期时间库,其精度只有秒级别,这对于有高精度要求的程序来说,是不够的。但这个问题在C++11 中得到了解决,C++11 中不仅扩展了对于精度的要求,也为不同系统的时间要求提供了支持。另一方面,对于只能使用 C-style 日期时间库的程序来说,C++17 中也增加了 timespec 将精度提升到了纳秒级别。
我花了一个星期,做出了公司的管理系统,只需几个步骤! 我是企业的管理人员,公司发展到现阶段,感觉进入到了瓶颈期,每个员工的工作都已经饱和,很难再挤出时间做其它的事情,需要一款合适的管理软件来协作我们的工作。本来打算买一套管理软件就行了,现实却并没有那么简单。