Date Time format in Flutter dd/MM/YYYY hh:mm

DartFlutter

Dart Problem Overview


My Date-Time format at the moment is this

By using this :

Text(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000).toString(), 

I am getting the type of format attached in the picture, however I was wondering if I could get it in dd/MM/YYYY hh:mm??

Dart Solutions


Solution 1 - Dart

If you use the intl package

final f = new DateFormat('yyyy-MM-dd hh:mm');

Text(f.format(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000)));

Solution 2 - Dart

Use intl package:

import 'package:intl/intl.dart';

The following code converts 31/12/2000 23:59 to 12/31/2000 11:59 PM

var inputFormat = DateFormat('dd/MM/yyyy HH:mm');
var inputDate = inputFormat.parse('31/12/2000 23:59'); // <-- dd/MM 24H format

var outputFormat = DateFormat('MM/dd/yyyy hh:mm a');
var outputDate = outputFormat.format(inputDate);
print(outputDate); // 12/31/2000 11:59 PM <-- MM/dd 12H format

Solution 3 - Dart

First install the pub.dev/packages/intl package in your pubspec.yaml

   intl: ^0.16.1

Then use

   final df = new DateFormat('dd-MM-yyyy hh:mm a');
   int myvalue = 1558432747;
   print(df.format(new DateTime.fromMillisecondsSinceEpoch(myvalue*1000)));

Output

> 21-05-2019 10:59 AM

Solution 4 - Dart

You can use date_format plugin available here https://pub.dartlang.org/packages/date_format

Then to convert,

formatDate(DateTime.now(), [dd, '/', mm, '/', yyyy, ' ', HH, ':', nn])

Solution 5 - Dart

If you use the intl package:

var date = DateTime.fromMicrosecondsSinceEpoch(miliseconds * 1000)
DateFormat(DateFormat.YEAR_MONTH_DAY, 'pt_Br').format(date.toUtc())

Output: 10 de abril de 2020

Solution 6 - Dart

/// Get date as a string for display.
String getFormattedDate(String date) {
  /// Convert into local date format.
  var localDate = DateTime.parse(date).toLocal();

  /// inputFormat - format getting from api or other func.
  /// e.g If 2021-05-27 9:34:12.781341 then format should be yyyy-MM-dd HH:mm
  /// If 27/05/2021 9:34:12.781341 then format should be dd/MM/yyyy HH:mm
  var inputFormat = DateFormat('yyyy-MM-dd HH:mm');
  var inputDate = inputFormat.parse(localDate.toString());

  /// outputFormat - convert into format you want to show.
  var outputFormat = DateFormat('dd/MM/yyyy HH:mm');
  var outputDate = outputFormat.format(inputDate);

  return outputDate.toString();
}

Solution 7 - Dart

var dateInFormatText = widget.snapshot["date"].toString().split("/");

DateTime dateResult = new DateTime.utc(
int.parse(dateInFormatText[2]),     
int.parse(dateInFormatText[1]), 
int.parse(dateInFormatText[0]));

Solution 8 - Dart

try this

Method:

    getFormatedDate(_date) {
      var inputFormat = DateFormat('yyyy-MM-dd HH:mm');
      var inputDate = inputFormat.parse(_date);
      var outputFormat = DateFormat('dd/MM/yyyy');
    return outputFormat.format(inputDate);
    }

Call:

getFormatedDate(_start_date)// simple date in string format

output:

24/05/2021

Solution 9 - Dart

you can use date_format package to format dates in flutter.

import 'package:date_format/date_format.dart';

final formattedStr = formatDate(DateTime.now(), [dd, '/', mm, '/', yyyy, ' ', HH, ':' nn]);

//02-03-2021

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionheyrView Question on Stackoverflow
Solution 1 - DartvbandradeView Answer on Stackoverflow
Solution 2 - DartCopsOnRoadView Answer on Stackoverflow
Solution 3 - DartSilenceCodderView Answer on Stackoverflow
Solution 4 - DartVinoth KumarView Answer on Stackoverflow
Solution 5 - DartFrancisco SalesView Answer on Stackoverflow
Solution 6 - DartAnit KumarView Answer on Stackoverflow
Solution 7 - DartHeitor Alves Rodrigues NetoView Answer on Stackoverflow
Solution 8 - DartSandeep PareekView Answer on Stackoverflow
Solution 9 - DartRavi LimbaniView Answer on Stackoverflow