flutter - 更改格式DateTime

标签 flutter dart

将“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/

相关文章:

dart - Flutter 应用程序错误 - 在 null 上调用了 getter 'value'

web - 如何连接到 Android 模拟器的本地主机?

flutter - 状态与类变量及其值是否相同?

firebase - 在 Flutter 中使用 streamBuilder 时条件不起作用

flutter - 如何在 IntelliJ 控制台中过滤 Flutter 应用程序的日志记录?

json - 如何在flutter中解码大型json数组

flutter - Android 上的 Diffie Hellman 和 AES

dart - 对于 dartjs 什么是字母表( A 到 Z )空类实例的奇数列表?

web-services - 如何从 Flutter/Dart Soap Web 服务 asmx 调用中获取值(value)?

object - 在 Three.Dart 中加载一个对象