IOS gets the current time and shows walking on the view

Source: Internet
Author: User

//

Rootviewcontroller.m

// time stamp is walking and shows Demo

//

Created by Dubai on 15/4/2.

Copyright (c) year Dubai. All rights reserved.

//


#import "RootViewController.h"


@interface rootviewcontroller ()

{

UILabel *labeltime;

Nstimer *timenow;


}


@end


@implementation Rootviewcontroller


-(void) Viewdidload {

[superviewdidload];

Additional setup after loading the view.

self. View. BackgroundColor = [uicolororangecolor];


labeltime = [[UILabelalloc] initwithframe: CGRectMake( Max, Max, )];

labeltime. BackgroundColor = [uicolorredcolor];

[Self. View addsubview:labeltime];

    timenow = [ nstimer Scheduledtimerwithtimeinterval: 1.0f target: self selector: @ Selector (timerfunc) userinfo: nil repeats: yes ];

// Get system time

nsdate * senddate=[nsdatedate];

nsdateformatter *dateformatter=[[nsdateformatteralloc] Init ];

[DateformatterSetdateformat:@ "hh:mm"];

nsstring * locationstring=[dateformatter stringfromdate: senddate];

NSLog (@ "-------%@", locationstring);

// Get system time

Nscalendar * cal=[nscalendar currentcalendar];

nsuinteger unitflags=nsdaycalendarunit| Nsmonthcalendarunit| Nsyearcalendarunit;

nsdatecomponents * conponent= [cal components: unitflags fromdate: senddate];

nsinteger year=[conponent year];

Nsinteger month=[conponent month];

nsinteger day=[conponent Day];

nsstring * nsdatestring= [nsstring stringwithformat:@ "%4d year %2d Month %2d day ", Year,month,day];

NSLog (@ "+++++++++++++%@", nsdatestring);

}

-(void) Timerfunc

{


nsdateformatter *formatter = [[nsdateformatteralloc] init ];

[Formatter setdateformat:@ "Mm/dd/yy HH:mm:ss"];

nsstring *timestamp = [Formatter stringfromdate: [nsdate date]];

[labeltimesetText: timestamp]; // time in a changing statement

NSLog (@ "%@", timestamp);





}


-(void) didreceivememorywarning {

[superdidreceivememorywarning];

//Dispose of any resources, can be recreated.

}


/*

#pragma mark-navigation


In a storyboard-based application, you'll often want to do a little preparation before navigation

-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {

Get The new view controller using [Segue Destinationviewcontroller].

Pass the selected object to the new view controller.

}

*/


@end


IOS gets the current time and shows walking on the view

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.