Dart Intl DateFormat.parse -1 year difference, bug? - flutter

when I execute this line of code:
DateTime dt = DateFormat("EEEE dd.MM.yyyy HH:MM").parse("Monday 01.12.2019 17:00");
print("dt.tostring: " + dt.toString()); //2018-12-01 17:00:00.000
The date is getting parsed from 2019 to 2018.
Tried 2020 and that is getting parsed to 2019.
Looks like a bug to me. Shall I make an Issue?
Wanted to ask here to make sure.
intl: ^0.16.1

DateTime dt = DateFormat("EEEE dd.MM.yyyy HH:mm").parse("Monday 01.12.2019 17:00");
you need to use lower-case 'mm' for minutes

Related

How to filter year in DateFormat for the current year?

I'm trying to create a TimeSeriesChart with a specific DateTimeTickFormatterSpec that formats dates in the current year as MMM and everything else as yMMM. In other words, the month should always be shown and the year should only be shown if it's not the current year.
01-01-2020 => Jan 2020
12-01-2021 => Dec 2021
01-01-2022 => Jan
I'm currently looking at charts.BasicNumericTickFormatterSpec.fromNumberFormat() which takes in a DateFormat for formatting the chart's ticks. Addressing the DateFormat for this case appears to be the simplest approach to me.
I wanted to ask if anyone knew if a conditional DateFormat is achievable or if anyone had any insight on using DateTimeFormatterFunction to achieve the above.
Thanks.
NVM, figured it out.
You'll want to use charts.AutoDateTimeTickFormatterSpec and specify a function along with your 2 DateFormats. In my case, currentYear contains MMM and previousYear contains yMMM.
tickFormatterSpec: charts.BasicDateTimeTickFormatterSpec((date) =>
date.year == DateTime.now().year
? currentYear.dateTickFormatter!.format(date)
: previousYear.dateTickFormatter!.format(date))

Flutter/Dart DateFormat 12:27 to 00:27 bug, hour 0 bug

I have a problem with Dart intl package while using DateFormat:
formatDateTime(DateFormat("yyyy-MM-dd hh:mm").parse(fortune.readFinishedAt ?? "2025-12-27 12:27:45"))
When I use this code, I want to take 12:27 for the hour part but DateFormat gives 00:27 to me.
hour property is 0.
How can I solve this issue?
If you need to the 24 hour format use this DateFormat("yyyy-MM-dd HH:mm").
use formate like I mention below:-
formatDateTime(DateFormat("yyyy-MM-dd hh:mm a").parse(fortune.readFinishedAt ?? "2025-12-27 12:27:45")),
use hh:mm a it will gave you time in am/pm formate
It seems like you want to use 12 hr time period
use formate like I mention below:-
if yopu want to use 12 hr time
use (hh:mm) a insted of (hh:mm)it will gave you time in am/pm formate
formatDateTime(DateFormat("yyyy-MM-dd hh:mm a").parse(fortune.readFinishedAt ?? "2025-12-27 12:27:45"))
Use this,
formatDateTime(DateFormat("yyyy-MM-dd h:mm:ss").parse(fortune.readFinishedAt ?? "2025-12-27 12:27:45")),
For more info : https://api.flutter.dev/flutter/intl/DateFormat-class.html

How to use to_date and IFERROR in Google Sheets together?

I have a date in format Wed, 09 Dec 2020 10:57:15 GMT and want turn it into 09/12/2020.
If i do it with =to_date(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b"))) it works - the output is, like expected 09/12/2020.
But if i add IFERROR, like =iferror(to_date(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b"))),"") the date turns into value, like 44174.
How can i achive the correct date displaying with iferror?
use:
=IFERROR(TEXT(DATEVALUE(REGEXEXTRACT(B2, "\b[0-9]{2}\s\D{3}\s[0-9]{4}\b")),
"dd/mm/yyyy"))
I'm not positive why it works, but the following - just built on what you'd done - worked for me:
=IFERROR(to_date(text(to_date(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b"))),"mm/dd/yyyy")))
BTW, i figured it out to get date displayed through changing of the order of IFERROR and TO_DATE.
The working formula is now =to_date(iferror(DATEVALUE(REGEXEXTRACT(B2,"\b[0-9]{2}\s\D{3}\s[0-9]{4}\b")),"")).

Change date format on dart

I am retrieving a date from api in this format, e.g "2020-03-02". But i need to a render it as this format e.g, "Tuesday, March,2020". I have been unable to find consice solution to this with flutter. Any help?
Use intl plugin
print(DateFormat('EEEE, MMM, yyyy').parse(dateString)); // prints Tuesday, mar, 2020
//OR
print(DateFormat('yyyy, MMM, EEEE').parse(dateString)); // prints 2020, mar, Tuesday

Moment JS setting TimeZone to EST - alloy/moment

I am using momentjs in alloy framework in Appcelerator. My api returns the date as - 2017-09-06T12:03:00.000Z I am using below code to format this date into readable form -
var dt = moment(record.createddate);
$.dateValue.text = moment(dt).format('lll');
But the output I get is - Sep 6, 2017 5:33 PM, which is not correct as the date saved in db and returned from api is EST and the date getting displayed is GMT+0530. How should i format this date so that I get the correct date value?
I guess, somewhere in your code, the moment's default timezone is set to GMT+0530. Something like moment.tz.setDefault('Asia/Colombo') could do this.
You can define in what timezone you want to display your date. This should work for you :
moment('2017-09-06T12:03:00.000Z').tz("Etc/GMT").format('lll')
Or if you want the value I suggested in the comments :
moment('2017-09-06T12:03:00.000Z').tz("Etc/GMT-2").format('lll')
For more informations about moment.js timezones, you can check the moment.js timezone docs.
Hope this helps !