Why does my NSDateFormatter sometimes return an a.m. or p.m. with yyyyMMddHHmmssSSS

需要设置Locale

NSDateFormatter *dateFormatter = [[[NSDateFormatter
alloc]
init] autorelease];

[dateFormatter
setDateFormat:@"yyyyMMddHHmmss"];

NSDate *currentDate = [[[NSDate
alloc] init]
autorelease];

[dateFormatter setCalendar:[NSCalendar
autoupdatingCurrentCalendar]];

[dateFormatter setLocale:[[[NSLocale
alloc] initWithLocaleIdentifier:@"en_US"]
autorelease]];

NSString *strDate = [dateFormatter
stringFromDate:currentDate];

http://stackoverflow.com/questions/7072267/why-does-my-nsdateformatter-sometimes-return-an-a-m-or-p-m-with-yyyymmddhhmmss

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-30 00:19:04

Why does my NSDateFormatter sometimes return an a.m. or p.m. with yyyyMMddHHmmssSSS的相关文章

【学习ios之路:Objective-C】block块语法.NSDate和NSDateFormatter

一.Block块语法 块语法:可以在函数内部定义匿名函数 格式: ^返回值类型(参数列表){函数体}其中返回值类型可以省略 block简单练习: ①.求两个数的最大值 //int (^)(int,int)//block类型 int (^max)(int,int) = ^(int a,int b) {//block的实现体 return a > b ? a : b; }; int value = max(4,6);          printf("%d",value); ②.将一

swift NSDateFormatter

// //  TimeViewController.swift //  UIControlDemo // //  Created by  on 14/12/10. //  Copyright (c) 2014年 马大哈. All rights reserved. // import UIKit class TimeViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() self.

类的扩展(Extension , NSData, NSDateFormatter, Category, Extension, Protocol, delegate)

类的扩展         OC数据类型         1.NSInteger, NSUInteger         2.CGFloat         3.NSString, NSMutableString         4.NSArray, NSMutableString         5.NSNumber         6.NSDictionary, NSMutableDictionary         7.NSSet, NSMutableSet              NSD

ios开发之NSDateFormatter,NSDate 与NSString日期转换,NSString任意格式互转

一般用java+oracle写的后台,可能给你返回的时间样式是这样的: 2014-01-20  13:24:33 看一下这个时间串是比较复杂,但是ios 的SDK已经为我们封装好了,把NSString 转换为 任意的NSDate 或者 NSString 使用NSDateFormatter 实现 + (NSString *)timeFromString:(NSString *)timeString { NSDateFormatter *formatter = [[NSDateFormatter a

iOS一个时间距现在的时间方法 intervalSinceNow NSDateFormatter

- (NSString*)intervalSinceNow:(NSString*)theDate { NSArray* timeArray = [theDate componentsSeparatedByString:@"."]; theDate = [timeArray objectAtIndex:0]; NSDateFormatter* date = [[NSDateFormatter alloc] init]; [date setDateFormat:@"yyyy-MM

iphone--有关日历中NSDateFormatter中英文

在使用日历使用中,获取星期的时候 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"EEE"];得到的String 是 “Mon” “Wed”.... 如果想要得到中文 “周一” “周三” 的可以用以下的方法: NSLocale *zh_Locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh

31-40(PHC文件,UIApplication,Info.plis,监听return按钮,格式化日期,openURL)

31.监听return按钮 32.自动滚动表格到最后一行 33.格式化日期 34.返回每一组需要显示的头部标题 35.Info.plist常见的设置 36.PHC文件 37.UIApplication 38.UIApplication的常用属性 39.iOS7中的状态栏 40.openURL { 一个合格的程序员是不会写出 诸如 "摧毁地球" 这样的程序的,他们会写一个函数叫 "摧毁行星"而把地球当一个参数传进去. } 31.点击了return按钮(键盘最右下角的按

NSDate NSDateFormatter

1.0 获取系统时间和年月日 计算年龄 //获得系统时间 NSDate *  senddate=[NSDate date]; NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"HH:mm"]; NSString *  locationString=[dateformatter stringFromDate:senddate]; //[datefor

IOS开发—NSDateFormatter

格式化参数如下: G: 公元时代,例如AD公元 yy: 年的后2位 yyyy: 完整年 MM: 月,显示为1-12 MMM: 月,显示为英文月份简写,如 Jan MMMM: 月,显示为英文月份全称,如 Janualy dd: 日,2位数表示,如02 d: 日,1-2位显示,如 2 EEE: 简写星期几,如Sun EEEE: 全写星期几,如Sunday aa: 上下午,AM/PM H: 时,24小时制,0-23 K:时,12小时制,0-11 m: 分,1-2位 mm: 分,2位 s: 秒,1-2位