通过使用这个:
Text(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000).toString(),
Run Code Online (Sandbox Code Playgroud)
我正在获得图片中附加的格式类型,但我想知道我是否可以获得它dd/MM/YYYY hh:mm?
vba*_*ade 21
如果使用intl包:
final f = new DateFormat('yyyy-MM-dd hh:mm');
Text(f.format(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000)));
Run Code Online (Sandbox Code Playgroud)
Sil*_*der 17
首先在你的 pubspec.yaml 中安装pub.dev/packages/intl包
intl: ^0.16.1
Run Code Online (Sandbox Code Playgroud)
然后使用
final df = new DateFormat('dd-MM-yyyy hh:mm a');
int myvalue = 1558432747;
print(df.format(new DateTime.fromMillisecondsSinceEpoch(myvalue*1000)));
Run Code Online (Sandbox Code Playgroud)
输出
21-05-2019 上午 10:59
Cop*_*oad 16
使用intl包:
import 'package:intl/intl.dart';
Run Code Online (Sandbox Code Playgroud)
以下代码转换31/12/2000 23:59为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
Run Code Online (Sandbox Code Playgroud)
Vin*_*mar 14
您可以使用date_format此处提供的插件https://pub.dartlang.org/packages/date_format
然后转换,
formatDate(DateTime.now(), [dd, '/', mm, '/', yyyy, ' ', HH, ':', nn])
Run Code Online (Sandbox Code Playgroud)
/// 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();
}
Run Code Online (Sandbox Code Playgroud)
小智 5
如果您使用intl 包:
var date = DateTime.fromMicrosecondsSinceEpoch(miliseconds * 1000)
DateFormat(DateFormat.YEAR_MONTH_DAY, 'pt_Br').format(date.toUtc())
Run Code Online (Sandbox Code Playgroud)
输出: 2020 年 4 月 10 日