Featured
-
Objective C or Swift - Which Technology to Learn for iOS Development?
Swift programming language is completely based on
by siddharth.sindhi -
Make UIImage White Background Transparent in iOS
If you came across to a requirement where you want
by ashish.nakoti -
User's location update on server when app is in background.
Code for those Apps where we need to update user's
by ashish.nakoti -
Animate button with zoom and bounce effect in ios
Many social apps are using bouncing effect for but
by ashish.nakoti -
Crop an image from UIImageView
With the following method stated below you can cro
by kuldeep.butola
Tags
Convert NSDate from local timezone to UTC and vice versa in Swift 3.0
1. To convert UTC(Coordinated Universal Time) to Local timezone
func convertToLocalDateFromUTCDate(dateStr : String) -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
let...
How to find the day of week?
Suppose we want to find the day of the week according to the given date i.e if we want to know the week day of a particular date then the following lines of code will help you to implement this :-
NSDate *date = [NSDate date]; //...
Convert NSDate into UTC
Coordinated Universal Time (UTC) is the standard time zone. All time zones are at some time ahead or behind UTC. If there is a need to convert timeZones of different countries then we can first change the local time to UTC and then to the desired...
How to convert NSDate from local timezone to UTC and vice versa in objc
1. To convert UTC to local time zone
- (NSString *)convertLocalDateFromUTCDate:(NSString *)dateStr{
NSDateFormatter *formatter = [self dateFormatter];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSDate *sourceDate...
How to convert from NSSTRING TO NSDATE ?
// date from string
NSString *dateString = [NSString stringWithFormat:@"%@",_model.time]; // model.time is the field in which we are fetching the string.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFo...
Compare two dates in iOS
To compare two dates we can use the following code :
NSComparisonResult result = [mydate1 compare:mydate2];
//where mydate1 and mydate2 are two dates we want to compare.
if (result == NSOrderedDescending) {
//mydate1 is later than myda...
Some helpful date related code
Get a date after n days
-(NSDate*)getNextDayAfterDays:(int)numOfDays from:(NSDate*)date
{
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *offsetComponents = [[NSDateCom...