NSDATE in ios with time zone - nsdate

i have a string 2013-03-17 08:41:16 +0000 i want to convert that into something like this Sun Feb 24 2013 00:00:00 GMT+0530 (India Standard Time) iam successful in getting like this Feb 24 2013 00:00:00 GMT 0530 India Standard Time .but i want the plus sign and brackets to be there .Any help willbe highly appreciated thanks. I have tried the following
NSDateFormatter *dateFormatter=[NSDateFormatter new];
[dateFormatter setDateFormat:#"yyyy-MM-dd HH:mm:ss z"];
NSDate *date=[dateFormatter dateFromString:txtStartDate.text];
[dateFormatter setDateFormat:#"EEE MMM dd yyyy HH:mm:ss +zzz (zzzz)"];
NSLog(#"%#",[dateFormatter stringFromDate:date]);
startDate = [NSString stringWithFormat:#"%#",[dateFormatter stringFromDate:date]];

Related

Impala convert string to timestamp in format 'Fri Mar 02 00:00:00 GMT 2018'

I want to convert a string field to timestamp with Impala.
I tried using this expression which works fine in Hive:
select from_unixtime(unix_timestamp('Fri Mar 02 00:00:00 GMT 2018','EEE MMM dd HH:mm:ss z yyyy')) AS Date_Call_Year;
but I get the error "Bad date/time conversion format: EEE MMM dd HH:mm:ss z yyyy". What is wrong with this format?

How to produce date object using moment.js

How to produce a similar new Date() object using moment.js?
I have input as UTC date and output should be similar to new Date() object.
Please help to resolve this.
Input: 1389033000000
Output: Tue Jan 07 2014 00:00:00 GMT+0530 (India Standard Time)
You can use moment().format(pattern), where pattern is a string describing the format you want.
Something like this should work:
const input = 1389033000000
const output = moment(input).format("ddd MMM DD YYYY hh:mm:ss ZZ")
console.log(output)
// Mon Jan 06 2014 04:30:00 GMT-0200
console.log(new Date(input))
// Mon Jan 06 2014 16:30:00 GMT-0200 (Horário de Verão de Brasília)
Furthermore, you can convert a moment to native date with moment().toDate()
const input = 1389033000000
const output = moment(input).toDate()
console.log(output)
// Mon Jan 06 2014 16:30:00 GMT-0200 (Horário de Verão de Brasília)
Use Moment Timezone to convert time to particular timezone
var moment = require('moment-timezone');
var timestamp = 1389033000000;
var usingTimezone = moment(timestamp).tz("Asia/Kolkata").format("ddd MMM DD YYYY hh:mm:ss Z");
var usingOffset = moment(timestamp).utcOffset("+05:30").format("ddd MMM DD YYYY hh:mm:ss Z");
console.log(usingTimezone);
console.log(usingOffset);

NSDateFormatter starts in 2000, but NSDate starts in 2001

Does anyone know why NSDateFormatter starts in 2000, but NSDate starts in 2001?
let date = Date(timeIntervalSinceReferenceDate:0) is 00:00:00 UTC on 1 January 2001
but a NSDateFormatter that converts minutes (for example 11:00) to a NSDate, returns 2000-01-01 11:00:00 UTC
How is that possible?

Date from a string iOS

My dateString is like the following: Tue, 08 Nov 2011 08:42:35
I tried to parse it using NSDateFormatter and following is the code:
NSString *dateString = #"Tue, 08 Nov 2011 08:42:35";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"EEE, d MMM YYYY'T'HH:mm:ss"];
NSDate *publishedDate = [dateFormat dateFromString:dateString];
But it always returns nil to publishDate.
Please help me.
Thanks
Your date format string doesn't match your date string. The one you provided ("EEE, d MMM YYYY'T'HH:mm:ss") would match dates that look like "Tue, 8 Nov 2011T23:14:42". That's not what it should be.
Tue, 08 Nov 2011 08:42:35
EEE, dd MMM yyyy HH:mm:ss

How To Parse "Wed Sep 13 16:42:35 +0000 2010" in Objective C

There just isn't a unicode format for representing months in 3 characters. It is always Sept, which is done by using MMM. What about "Sep"?
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"EEE MMM dd HH:mm:ss ZZZZ yyyy"];
NSDate *myDate = [dateFormatter dateFromString:#"Wed Sep 13 16:42:35 +0000 2010"];
this should parse your sample string nicely.
I have tested it with "Sept" (four characters), it will not work.
but "Sep" is just fine.

Resources