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?
Related
I am exploring different date formats and trying to convert date formats to others. Currently, I m stuck in a scenario where I have input dates and times as below:
I was able to convert it to a date timestamp using concatenation
concat_ws(' ',new_df.transaction_date,new_df.Transaction_Time)
While I m trying to use
withColumn("date_time2", F.to_date(col('date_time'), "MMM d yyyy hh:mmaa")) with ('spark.sql.legacy.timeParserPolicy','LEGACY')
It is displayed as 'undefined'
I am looking for pointers/code snippets to extract YYYY-MM-DD HH:MM:SS in CET (input is in PST) as below
input_date_time
output (in CET)
Mar 1, 2022 01:00:00 PM PST
2022-03-01 22:00:00
Parse PST string to timestamp with timezone in UTC. Then convert to "CET" time:
import pyspark.sql.functions as F
df = spark.createDataFrame(data=[["Mar 1, 2022 01:00:00 PM PST"]], schema=["input_date_time_pst"])
df = df.withColumn("input_date_time_pst", F.to_timestamp("input_date_time_pst", format="MMM d, yyyy hh:mm:ss a z"))
df = df.withColumn("output_cet", F.from_utc_timestamp("input_date_time_pst", "CET"))
[Out]:
+-------------------+-------------------+
|input_date_time_pst|output_cet |
+-------------------+-------------------+
|2022-03-01 21:00:00|2022-03-01 22:00:00|
+-------------------+-------------------+
Note - The 2022-03-01 21:00:00 above is Mar 1, 2022 01:00:00 PM PST displayed in UTC.
Epoch time for 2nd July 2018 , 11 PM. (IST)
> moment('2018-07-02T23:00:00.000').unix()
1530552600
Now When I convert from epoch to IST, It added 7 minute Extra.
> moment.unix(1530552600).tz("Asia/Kolkata").format("DD:MM:YYYY HH:MM z");
'02:07:2018 23:07 IST'
When converted to ET timezone , It gives 30 minute less from IST timezone. ET is 9.5 behind IST so it should have been "02:07:2018 01:30:00 EDT'
> moment.unix(1530552600).tz("America/New_York").format("DD:MM:YYYY HH:MM z");
'02:07:2018 13:07 EDT'
IST
your formatting string is wrong, you used MM (month) instead of mm (minutes)
try
moment.unix(1530552600).tz("Asia/Kolkata").format("DD:MM:YYYY HH:mm z");
for all other formats see the moment documentation
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]];
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
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.