Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-20-2011, 06:01 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 3
king85 is on a distinguished road
Default how to display time as hour:min format ?????

hi i am new to objective C . i am writing a program where the data's are given , in the output it should display name , id no and enter and exit time and total time spend in office.
i want the time format to show in hour:min format for ex 10:00 idk how to put it , any help would be great

Code:
#import <Foundation/Foundation.h>

@interface employee : NSObject 
{
    NSString *name;
    int idno;
    int entertime;
    int exittime;
}

-(void) print;
-(void) setName : (NSString*) nn;
-(void) setId : (int) iden;
-(void) setentertime : (int) enter;
-(void) setexittime : (int) exit;

-(void) totaltime;

@end

@implementation employee

-(void) print
{
    NSLog(@"The name = %@",name);
    NSLog(@"The id number of the employee = %i",idno);
    NSLog(@"The entertime of the employee = %i",entertime);
    NSLog(@"The exittime of the employee  = %i",exittime);
}

-(void) setName : (NSString*) nn;
{
    name=nn;
}

-(void) setId : (int) iden;
{
    idno=iden;
}

-(void) setentertime : (int) enter;
{
    entertime = enter;
}

-(void) setexittime : (int) exit;
{
    exittime=exit;
}

-(void) totaltime
{
    int totaltime;
    totaltime=exittime-entertime;
    
    NSLog(@"Employee worked for %2i hours",totaltime);
    
}

@end


int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   
    employee *myemployee;
    
    myemployee=[[employee alloc]init];
    

    [myemployee setName:@"rahul"];
    [myemployee setId:23];
    [myemployee setexittime:17];
    [myemployee setentertime:10];
    
    [myemployee print];
    [myemployee totaltime];
     
    [pool drain];
    return 0;
}
king85 is offline   Reply With Quote
Old 06-20-2011, 07:07 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: France
Posts: 31
krag is on a distinguished road
Default

Take a look at NSDateFormatter class

NSDateFormatter Class Reference
krag is offline   Reply With Quote
Old 06-20-2011, 07:53 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 3
king85 is on a distinguished road
Default

i dont want to use NSDateFormatter Class Reference

can i use it using simple program like we do it in c/c++

like using mod or something
king85 is offline   Reply With Quote
Old 06-20-2011, 08:14 PM   #4 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

What..... Why don't you want to use NSDateFormatter? It'll take maybe 3 lines of code.
Domele is offline   Reply With Quote
Old 06-21-2011, 12:27 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 3
king85 is on a distinguished road
Default

Quote:
Originally Posted by Domele View Post
What..... Why don't you want to use NSDateFormatter? It'll take maybe 3 lines of code.
cause i want write in basic program cause i dont know how to do it NSdateformatter ..
i just want to try it out how we use it in C then later on when i get more familiar with objective C i'll use NSdateformatter.

idk how to do it in C
king85 is offline   Reply With Quote
Old 06-27-2011, 11:15 PM   #6 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: Sydney, Australia
Posts: 44
new2objectivec is on a distinguished road
Default

Instead of getting stuck with things like this, how about write a separate method which returns a string to display the time in the required format.

Then you can separate your main code from the "what-ever-language/method" used to display the time correctly.

For now, put in the NSDateFormatter or whatever method in there first, just to make your whole application working. I found this example on the net: http://ykyuen.wordpress.com/2010/06/...dateformatter/

Later, you can "improve" that method and re-write it with whatever better language you like. (which might never happen :-P ...)

Last edited by new2objectivec; 06-27-2011 at 11:21 PM.
new2objectivec is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 476
16 members and 460 guests
7twenty7, AlanFloyd, AppsBlogger, David-T, HemiMG, iAppDeveloper, imac74, Jaxen66, lovoyl, Music Man, mutantskin, Paul Slocum, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:15 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0