Invalid date format [Flutter] [duplicate] - flutter

This question already has answers here:
How do I convert a date/time string to a DateTime object in Dart?
(8 answers)
Closed 9 months ago.
I've been trying convert a String to DateTime in dart using DateTime.parse(dateStart), where 'dateStart' is my variable that I use to get the date, for example in the next format '24/12/2022', but I catch invalid date format, I would like to known which are the validates formats to use in dart.
DateTime.parse(dateStart)

You need to use intl package to parse string date to datetime object. Please check sample Datetime parse example as below.
DateTime tempDate = new DateFormat("dd/MM/yyyy").parse(savedDateString);

You can format '24/12/2022' to DateTime like this:
final dateTime = DateFormat('dd/MM/yyyy').parse('24/12/2022');

Related

Flutter rounds DateTime value to 3 decimal places [duplicate]

This question already has an answer here:
DateTime.fromMillisecondsSinceEpoch not returning an exact DateTime object
(1 answer)
Closed last month.
I'm developing a web app using Flutter front-end and FastApi. I encountered this issue while using DateTime, that its value has a different length in either of the languages (Python & Dart).
DateTime object from python
2022-01-25T13:09:03.914910
DateTime object parsed from response
2022-01-25 13:09:03.915
I observed that Dart rounds the DateTime value to 3 decimal places.
How to get around this issue.
You're probably using the default toString() on the DateTime object. What you might need is the toIso8601String() method. Here's a code sample to show the difference.
final now = DateTime.now();
print(now); // 2022-01-25 11:04:08.053
print(now.toIso8601String()); // 2022-01-25T11:04:08.053

Converting number of years to date using dart

I've been trying to convert number of years to date using dart. The format has to be YYYY-MM-DD. There is 19 years for example and I'm trying to get 2001-02-12 programmatically.
I've also tried looking for a library here but I can't find any that can help me In this case. Thank you.
for date format you can use DateFormatter fomatter = 'yyyy-MM-dd'; , DateTime date = DateTime(year: year); to create the date with the correct year. Then you can format the date. String formattedDate = formatter.format(date);.
Choose appropriate string format value for formatter and type for formattedDate and done.
Cheers

How to split Japanese Date which include month and year into or Date format [duplicate]

This question already has answers here:
How does Java "week year" really work?
(2 answers)
Why I get a wrong result when parsing a date from string with SimpleDateFormat ? (Java) [duplicate]
(1 answer)
java parsing string to date
(2 answers)
Is SimpleDateFormat in Java work incorrect or I did any mistake? See code sample [duplicate]
(2 answers)
Closed 2 years ago.
I want to split Japanese date which is in format "2020年7月" into separate array so that can get the year and month from that.
I tried SimpleDateFormatter to format Japanese date with and have the year and date separated with "/"but the output is wrong:
Tried this code:
val inputFormat = SimpleDateFormat("YYYY年M月")
val date = inputFormat.parse("2020年7月")
val outputText = SimpleDateFormat("YYYY/MM").format(date)
input :2020年7月
output:2020/12
Can anyone help me in this?
You should be using java.time for this because the datetime classes from java.util are outdated (but still not deprecated).
The following example shows a way using a java.time.format.DateTimeFormatter for parsing a String formatted according to a certain pattern and a java.time.YearMonth, a class obviously designed for the purpose of creating a month in a year without respect to a day of month:
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
fun main() {
val jpYearMonth = "2020年7月"
val japaneseDtf = DateTimeFormatter.ofPattern("uuuu年M月")
val yearMonth = YearMonth.parse(jpYearMonth, japaneseDtf)
println(yearMonth.format(DateTimeFormatter.ofPattern("uuuu/MM")))
}
In order to achieve your desired output this code has to use a different DateTimeFormatter defining the output pattern because the default pattern (internal use when you just println(yearMonth)) would be hyphon-separated (2020-07):
2020/07

Convert a date in string YYYY-MM-DD to MM/DD in JSTL [duplicate]

This question already has answers here:
Convert and format a Date in JSP
(6 answers)
Closed 5 years ago.
I have a string field that is shown as a date in YYYY-MM-DD format. I am trying to convert this field on my JSP to MM/DD date format. Here is the JSTL code I have now:
<fmt:parseDate var="taxFromDate" value="${a8spt214.fromDate}" pattern="MM-dd"/>
<fmt:parseDate var="taxToDate" value="${a8spt214.toDate}" pattern="MM-dd"/>
When I try running this I get a compile error saying the following
In <parseDate>, value attribute can not be parsed: "2017-06-30"] with root cause java.text.ParseException: Unparseable date: "2017-06-30"
is it possible to convert a string to a date filed in JSP without actually using the year in the format? Or is the pattern invalid?
Thanks
You can use this Code to show this type of date MM/DD/YY
<p>Formatted Date : <fmt:formatDate type = "both"
dateStyle = "short" timeStyle = "short" value = "${now}" /></p>
The Code above will Print this result:
Formatted Date : 23/09/10 14:27
I hope to help you solve problem.

converting a utc format date string to date object in Extjs

I have a date string in the format "2013-01-31T10:10:05.000Z". I want to convert this string to a Date object in extjs.
I have tried to use Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-dTH:i:s.uZ"). But it is returning undefined.
I also tried with new Date("2013-01-31T10:10:05.000Z"), but it is also returning undefined.
Note: I have tried in IE8 browser.
Could anyone please help me to convert the above date string to Date object?
Thanks a lot sra. Now I am getting the result as ...UTC+5:30... Is there any way to convert this in IST format?
Try Ext.Date.parse("2013-01-31T10:10:05.000Z","c");
The c is the format type for ISO 8601 formatted dates
See the Ext.Date API for more details on this or other available formats
That's because 'T' and 'Z' are special characters in the Date format: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date
You have to escape them like this: Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-d\\TH:i:s.u\\Z")