ios CCNSDate.m

objectivec 复制代码
//
//  CCNSDate.h
//  CCFC
//
//  Created by xichen on 11-12-17.
//  Copyright 2011年 ccteam. All rights reserved.
//


#import <Foundation/Foundation.h>




@interface NSDate(cc)
    
// 获取系统时间(yyyy-MM-dd HH:mm:ss.SSS格式)
+ (NSString *)getSystemTimeStr;


// print current time using printf func
+ (void)printCurrentTime;


// print the system date by chinese format
+ (void)printSystemDateByChineseFormat;




@end
cpp 复制代码
//
//  CCNSDate.m
//  CCFC
//
//  Created by xichen on 11-12-17.
//  Copyright 2011年 ccteam. All rights reserved.
//


#import "CCNSDate.h"




@implementation NSDate(cc)


// 获取系统时间(yyyy-MM-dd HH:mm:ss.SSS格式)
+ (NSString *)getSystemTimeStr
{
        NSDateFormatter *dateFormatter = [NSDateFormatter new];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];       // 设置格式为年-月-日 时:分:秒.毫秒
        
        NSString *timeStr = [dateFormatter stringFromDate:[NSDate date]];
        [dateFormatter release];
        
        return timeStr;
}


// print current time using printf func
+ (void)printCurrentTime
{
        printf("Current Time is %s\n", [[self getSystemTimeStr] UTF8String]);
}


// print the system date by chinese format
+ (void)printSystemDateByChineseFormat
{
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        //NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
        //[formatter setLocale:locale];
        //[locale release];
        
        [formatter setDateFormat:@"YYY年MM月d日EEEE"];
        NSDate *date = [NSDate date];
        NSLog(@"%@", [formatter stringFromDate:date]);
        [formatter release];
}


@end

微风不燥,阳光正好,你就像风一样经过这里,愿你停留的片刻温暖舒心。

我是程序员小迷(致力于C、C++、Java、Kotlin、Android、Shell、JavaScript、TypeScript、Python等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。

欢迎关注。助您在编程路上越走越好!

相关推荐
编程在手天下我有2 小时前
缓存与数据库数据一致性:旁路缓存、读写穿透和异步写入模式解析
数据库·缓存·oracle·软件开发·架构设计·数据一致性
余生大大3 小时前
关于Safari浏览器在ios<16.3版本不支持正则表达式零宽断言的解决办法
ios·正则表达式·safari
爱分享的程序员4 小时前
前端跨端框架的开发以及IOS和安卓的开发流程和打包上架的详细流程
android·前端·ios
Macle_Chen4 小时前
ios开发中xxx.debug.dylib not found
ios·bug·debug.dylib
万岳软件开发小城8 小时前
基于PHP+Uniapp的互联网医院源码:电子处方功能落地方案
开发语言·uni-app·php·软件开发·互联网医院系统源码·智慧医院app
WDeLiang20 小时前
Flutter 环境搭建
flutter·ios·visual studio code
lilili啊啊啊1 天前
iOS 应用性能测试工具对比:Xcode Instruments、克魔助手与性能狗
测试工具·ios·iphone·xcode·克魔
264玫瑰资源库2 天前
嘻游电玩三端客户端部署实战:PC + Android + iOS 环境全覆盖教程
android·ios
鸿蒙布道师2 天前
鸿蒙NEXT开发权限工具类(申请授权相关)(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
鸿蒙布道师2 天前
鸿蒙NEXT开发定位工具类 (WGS-84坐标系)(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei