in flutter dart convert 1624275605667 into Mon Jun 21 2021 17:10:05 GMT+05:30 - flutter

var date = 1624275605667;
final DateTime formatted = DateTime(date);
final DateFormat fr = DateFormat('EEE MMM d yyyy HH:mm:ss');
final String dd = fr.format(formatted);
I try like this but getting some type of errors.
I want to convert 1624275605667 into this format Mon Jun 21 2021 17:10:05 GMT+05:30
For this which format I use here
DateFormat('EEE MMM d yyyy HH:mm:ss zzz')

Please try this one
var date = 1624275605667;
final DateTime formatted = DateTime.fromMillisecondsSinceEpoch(date);
final DateFormat fr = DateFormat('EEE MMM dd yyyy HH:mm:ss');
final String dd = fr.format(formatted);
print(dd);
You are using z pattern and it's not implemented yet. Issue is still open since 2015 https://github.com/dart-lang/intl/issues/19
And in intl package already mentioned that this characters are reserved and currently are unimplemented.
For workaround you can use
formatted.timeZoneOffset.toString(); /// 5:30:00.000000
Which is same as GMT+05:30

Related

flutter HTTP date strings with DateFormat

intl: ^0.16.1
Can't seem to parse HTTP header date field with flutter DateFormat/HttpDate
here is what I tried:
var date = HttpDate.parse("Thu, 11 Feb 2021 10:53:15 +0200");
return error:
Invalid HTTP date Thu, 11 Feb 2021 10:53:15 +0200
Note: the string was received by package:googleapis/gmail/v1.dart
final zFormatDateEmailRFC2822 = DateFormat("EEE, d MMM yyyy HH:mm:ss Z");
var date = zFormatDateEmailRFC2822.parse("Thu, 11 Feb 2021 10:53:15 +0200");
return error:
Trying to read EEE from Thu, 11 Feb 2021 10:53:15 +0200 at position 0
The following is an example from https://api.flutter.dev/flutter/intl/DateFormat-class.html
final fmt = DateFormat('EEE, MMM d, ''yy');
var date = fmt.parse("Wed, Jul 10, '96");
return error:
Trying to read EEE from Wed, Jul 10, '96 at position 0
final fmt = DateFormat("d MMM yyyy");
var date = fmt.parse("11 Feb 2021");
return error:
Trying to read MMM from 11 Feb 2021 at position 3
final fmt = DateFormat("MMM");
var date = fmt.parse("Feb");
return error:
Trying to read LLL from Feb at position 0
The only thing that works for me is:
var dateStr = "Thu, 11 Feb 2021 10:53:15 +0200";
RegExp regExp = RegExp(r"(.*, \d+ .* \d+ \d+:\d+:\d+)");
if (regExp.hasMatch(dateStr)) {
var groups = regExp.firstMatch(dateStr);
var date = HttpDate.parse(groups[1] + " GMT");
print("date $date >${HttpDate.format(date)}<");
}
Try it:
final fmt = DateFormat("d MMM yyyy", "en_US");
var date = fmt.parse("11 Feb 2021");
I had to parse the email header date string
Somehow the other answers where not considering everything i needed and so i came up with the following solution which also takes care of the timezone +0200
DateFormat('E, d MMM yyyy hh:mm:ss Z', 'en_US').parse(DATE_STRING);
Input String : Wed, 18 Aug 2021 09:00:43 +0200
DateTime.toISo8601String() => 2021-08-18T09:00:43.000
DateTime.toUTC().toString() => 2021-08-18 07:00:43.000Z
If you want to learn more about the patterns please have a look at DateFormat

Which date format is this NSDate dateFormat?

I want to convert this string to NSDate,
Mon, 21 Mar 2016 10:26:45 GMT
so I set the date format to this:
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
but it returns nil.
I tried to change this format to:
E, dd MMM yyyy HH:mm:ss zzz
EEE, dd MMM yyyy hh:mm:ss zzz
EEE, d MMM yyyy HH:mm:ss zzz
but it also returns nil.
Which date format should I use?
Your format string is ok but you have to add a compatible locale to the formatter.
For example your string works well with the US locale:
let source = "Mon, 21 Mar 2016 10:26:45 GMT"
let dateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
let result = dateFormatter.dateFromString(source)
Try this code block :
let dateFormatter = NSDateFormatter()
let dateString = "Mon, 21 Mar 2016 10:26:45 GMT"
dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
let date = dateFormatter.dateFromString(dateString)
Try escaping the comma:
E',' dd MMM yyyy HH:mm:ss zzz
You can try the following code
let dateString:String = "Mon, 21 Mar 2016 10:26:45 GMT"
let dateFormat = NSDateFormatter.init()
dateFormat.dateStyle = .FullStyle
dateFormat.dateFormat = "ccc, dd MM yyyy HH:mm:ss zzz"
let date:NSDate? = dateFormat.dateFromString(dateString)
print(dateFormat.stringFromDate(date!))
For more info please visit NSDateFormatter formatting

Powershell Convert DateTime to dd mon yyyy

I want to convert a date to this format "dd Mon yyyy".
I have this code which works:
$date = [DateTime]::Parse("21/11/2014")
$dateFormatted = $date.GetDateTimeFormats()[12]
#$dateFormatted displays 21 November 2014
Is there a way to convert it using something like this?:
$dateFormatted = $date.ToString("dd Mon yyyy")
At the moment this returns "21 11on 2014"
I worked it out:
$dateFormatted = $date.ToString("dd MMMM yyyy")

Scala String to Java Util Date Conversion

Hi the Conversion of String to Date is not possible here..
I search and use several methods but the error can not change..
here the date format is var q and convert that to formatedDate that is String
then the String convert into util date..
SearchDate is from method parameter and the value of SearchDate is "Thu Aug 29 00:00:00 IST 2013"
var q: Date = SearchDate
var dateStr = q.toString()
var formatter: DateFormat = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy")
var dat = formatter.parse(dateStr)
var cal: Calendar = Calendar.getInstance()
cal.setTime(dat)
var formatedDate = cal.get(Calendar.DATE) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.YEAR)
println("formatedDate : " + formatedDate)
val date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr)// Error Occured Here..
the error is
Exception in thread "main" java.text.ParseException: Unparseable date: "Thu Aug 29 00:00:00 IST 2013"
at java.text.DateFormat.parse(Unknown Source)
please share your answers ..
You're trying to parse "E MMM dd HH:mm:ss Z yyyy" formatted date string as "yyyy-MM-dd HH:mm" formatted one, in this line:
val date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr)
No wonder it fails.
Maybe you took the wrong date format for second SimpleDateFormat instance by mistake? Or maybe you're passing wrong parameter to parse() ?
edit
It looks like you actually wanted to call:
val date = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(dat)

formatting date from twitter response Zend Framework

im trying to formatting the date field 'created_at' from Twitter API response with Zend_Date. I want output the date like this:
21 of July of 2009, 12:30:00 (for example)
What format is this?:
Fri Oct 23 15:47:42 +0000 2009
thanks a lot
I've had the best luck just doing
$d = new Zend_Date(strtotime($input));
$twitter_format_out = $d->toString('EEE MMM dd HH:mm:ss Z YYY');
These date are not looking a standard format. Therefore, you have to create a format with the right constants (see them here).
Your first example (21 of July of 2009, 12:30:00):
$format = "d ' of ' MMMM ' of ' YYYY, h:mm:ss";
Your second example (Fri Oct 23 15:47:42 +0000 2009):
$format = "EEE MMM d h:mm:ss Z YYYY";
This formats you can use both for importing a date
$date = new Zend_Date($string, $format);
Or for outputting
$date->toString($format);
Look in the manual for locale support etc.