English 中文(简体)
NSDateFormatter “Month”in 3封信,而不是全字
原标题:NSDateFormatter "Month" in 3 letters instead of full word
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd-MM-YYYY HH:mm"];        
    [formatter setTimeZone:[NSTimeZone systemTimeZone]];

If i choose MM i get the month in number: 09-05-2012 15:33 If i choose MMMM i get the month in word: 09-May-2012 15:33

What i wanted, was the month in 3 letters abbreviation.
Eg: January would be Jan

在本案中,5月份是正确的,因为只有3封信件。

最佳回答

曾尝试过:[formatter setDateFormat:@”dd-MMM-YYH:mm”];,然后[formatter stringFromDate:someNSDate];

问题回答

红十字与红新月联会将两件事情按错误顺序排列,你没有获得预期产出。

[formatter setDateFormat:@"MMM"];
[formatter setDateStyle:NSDateFormatterMediumStyle];

NOT提供的结果与:

[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setDateFormat:@"MMM"];

(这两条警示中的第二条警示正好在我的服中贴出Sep Oct等)

http://www.ohchr.org。

let dateFormatter = NSDateFormatter()

dateFormatter.dateFormat = "dd MMM yyyy HH:mm"

dateFormatter.stringFromDate(NSDate())

这是一项 stripped的解决方案,与快速4公司合作,产生了3个月的产出:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd MMM YYYY, HH:mm:ss"

核实:

print(dateFormatter.string(from: Date())) // 20 Mar 2018, 23:41:40

As previously noted, MMM is the correct syntax for getting the desired month output.

快速4:

if let dateFormatter = DateFormatter(){
    dateFormatter.dateStyle = .medium
    // eventually:
    //let locale = Locale(identifier: ...                       
    //dateFormatter!.locale = locale
    dateFormatter.dateStyle = .medium
    dateFormatter!.dateFormat = "dd MMM YYYY, HH:mm:ss"
 } else..
        ..

实际上,你可以把标题定在中(即Jan , Feb等):

[formatter setDateStyle:NSDateFormatterMediumStyle];

对于那些没有“MMM”整整一个月的人来说,你可以接手。

dateFormatter.dateFormat = "dd MMMM yyyy"

快速测试4.2





相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签