views:

116

answers:

2

i want to be get a date (the current hour) from strftime and get it into a nsstring in obj-c for the iphone-os

+3  A: 

I would recommend using NSDate's descriptionWithCalendarFormat:timeZone:locale:. More documentation about the call can be found here. The API allows you to specify which component from a date you want output to an NSString, which is the return result of the API.

Update: If you really want to use strftime then take the const char*-typed result from that call and convert it to an NSString* by using stringWithUTF8String. More info on that here.

fbrereto
yes i know that but i want to use strftime
DotSlashSlash
Can you detail a bit why you want to use `strftime` instead?
fbrereto
on the iphone os nsdate has a bug which i need to work around and i thought this would probably be the easiestthe bug is that it if you are on a regional format on your device which doesnt use 12hour format clock by default and the user has manually changed it to 12hour(via the switch) nsdate will give the time in 12hour with am/pm and such (the top one in the picture below). But if the device is set to a regional format such as US which 12hour is set automatically or the devices clock is on 24 (no matter what regional format) nsdate will give the time in 24 hour (the bottom 1 in the picture)
DotSlashSlash
http://i47.tinypic.com/2qsm1js.jpg
DotSlashSlash