将“selectedDate”分配给“dateBirthdayUser”时,如何更改格式?我需要像“31/12/2019”那样的“dateBirthdayUser”显示日期。
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class _ProfileState extends State<Profile> {
DateTime dateBirthdayUser = DateTime(1900, 01, 01, 00, 00, 00);
DateTime selectedDate = DateTime.now();
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
builder: (BuildContext context, Widget child) {
},
locale: Locale('es'),
context: context,
initialDate: selectedDate,
firstDate: DateTime(1950, 1),
lastDate: DateTime(2100));
if (picked != null && picked != selectedDate)
setState(() {
selectedDate = picked;
dateBirthdayUser = selectedDate;
});
}
最佳答案
check out this answer
您需要使用DateFormat类
import 'package:intl/intl.dart';
并将其用于不同的格式
Check official docs to date format class
关于flutter - 更改格式DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59394520/