Непоследовательное использование парсинга даты SimpleDateFormat

Можно попробовать это:

NSLog(@"%@", NSStringFromCGPoint(cgPoint));

существует много функций обеспечены UIKit, которые преобразовывают различные структуры CG в NSString с. Причина это не работает, состоит в том, потому что %@ показывает объект. CGPoint структура C (и так CGRect с и CGSize с.

10
задан Matt Ball 28 August 2010 в 14:58
поделиться

3 ответа

I think you want to use the HH format, rather than 'hh' so that you are using hours between 00-23. 'hh' takes the format in 12 hour increments, and so it assumes it is in the AM.

So this

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse("2009-08-19 12:00:00");
System.out.print(date.toString());

Should print out

Wed Aug 19 12:00:00 EDT 2009

25
ответ дан 3 December 2019 в 14:53
поделиться

The hour should be specified as HH instead of hh. Check out the section on Date and Time patterns in http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html

3
ответ дан 3 December 2019 в 14:53
поделиться

You're printing out the toString() representation of the date, rather than the format's representation. You may also want to check the hour representation. H and h mean something different. H is for the 24 hour clock (0-23), h is for the 12 hour clock (1-12), (there is also k and K for 1-24 and 0-11 based times respectively)

You need to do something like:

//in reality obtain the date from elsewhere, e.g. new Date()
Date date = sdf.parse("2009-08-19 12:00:00"); 

//this format uses 12 hours for time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//this format uses 24 hours for time
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

System.out.print(sdf.format(date));
System.out.print(sdf2.format(date));
2
ответ дан 3 December 2019 в 14:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: