I need to display the date ,time and time zone in given format "2020-07-08T02:44:58 +05:30".
I could display time and date but couldn't display timezone along with that.help please
You can use the function DateTime.now().timeZoneName that will output the timezone's name (EST, PST) if you need further enhancements, you could try this library: https://pub.dev/packages/flutter_native_timezone
I found the answer for getting timestamp for flutter.I used package date_format 1.0.8 https://pub.dev/packages/date_format. The package helps me to meet my requirement.
Related
In the "Activity for jobs' page in Rundeck the execution time has a relative time field (example: "Today at 10:15 AM" or "Last Sunday at 4:51 AM") after the timestamp.
It is easy to change the date format of the timestamp by adding jobslist...format[.ko] in the i18n/messages.properties file.
It seems impossible however to change the format of the relative time message. It seems to be hard-coded in en_US with AM/PM which doesn't look too good in in non-English-speaking countries. The format is always the same regardless of the ?lang=xx parameter or the default language in the browser. Interestingly, other objects (like hovering over the field with the mouse and the duration get translated).
Has anyone successfully changed this?
Example. See the duration field
I have been trying this with the docker images (4.8.0, 4.9.0 and SNAPSHOT)
I've looked at the source code and apparently this lies somewhere in the moment.js code.
In some parts, the date formats are hard coded as you say, please add your use case on this thread.
I was importing internationalization for my app but I have a problem where I parse my String but it only returns the date and not the time. When I change the phone language, my format for the Date changes but my Time isn't showing.
This is when it is EN_US
This is when it is EU(German)
That works well but my time format is missing...
This is the default String from the API:
Here is the code:
/// I set a variable that calls the locale of the phone language and changes according to the phone preference
final f = DateFormat.yMd(Localizations.localeOf(context).languageCode);
/// where I dispay time and date but only date is shown in the pictures above
Text('Time and date: ${f.format(DateTime.parse(apicall.dateCreated))}');
My questions are: How do I show the time and how can I swap between showing the Time first then the Date, and opposite, if I want to show the Date first then the Time? (example 18-May-21 11:10h and if I want to do this 11:10h 18-May-21)
Thanks in advance for the help!
I suppose you should use DateFormat.jm().add_yMd(): this will show time first and then date. To swap it just use DateFormat.yMd().add_jm()
More info here
The code is as follows:
DateTime time = DateFormat("hh:mm").parse(doc[i]["Time"]);
The doc[i]["Time"] value is supposed to be a military time like 19:42. I followed the guidelines about using DateFormat but the end result variable time contains "1970-01-01 19:42:00.000". Is there a way for time to just contain "19.42"?
To get time in 24hrs format change your code to
String time = DateFormat("HH:mm").format(doc[i]["Time"]);
H -> is for 24 hours format
It is not possible to use DateTime to show a specific format, must always become a String.
A DateTime type will always store everything including year, month, hour, minutes, seconds, milliseconds, etc.
But when you later use the variable, you can chose what to display.
For example, you can chose to display just the military time. Here is one example using the Intl package (here)
Text(DateFormat('Hm').format(yourVariable))
Don't forget to import
import 'package:intl/intl.dart';
I am developing a Flutter project and I want to get 'timestamp' data from firestore and display that value using 'yyyy-MM-dd hh:mm' format. How can I do it ?
Firestore will give you back a Timestamp object as I think you've figured out. It has a method .toDate() which will return a dart DateTime object.
Once you have the Date object, then you should use the DateFormat class as someone so helpfully pointed out in a comment without even linking to the documentation.
That would look something like this:
DateTime date = timestamp.toDate();
DateFormat(yyyy-MM-dd hh:mm").format(date);
although I haven't tested out the format function and dartpad doesn't seem to support the intl package, so you may need to play around with the format codes a bit.
I am trying to compare and check the date if it is today's date or not in a spesific program. I tried to use assertion method but when I use it the time will remain same if you try it next day. The main problem that I need to know when open a page from program It should be today's date and should be passed. if you know already anything about it please let me know also :)
Thanks yo!
Use System.DateTime.Now.ToString("yyyy-MM-dd") as one argument of the assertion. You may need to use a different format rather in the ...ToString() method. The exact format depends on how the date is shown on the screen.
This could be done using "StringAssert" to verify that your programs date string contains today's date string, while ignoring the time:
var programDateString = "7/25/2016 12:00:00"; //this is an example of your date retrieved from the application with time included
var todaysDate = System.DateTime.Today.ToShortDateString(); //short date string
StringAssert.Contains(programDateString, todaysDate);