var oldDate = DateTime.parse('2023-01-25T00:37:00.000Z');
var newDate = DateFormat('MM/dd/yyyy hh:mm a').format(oldDate);
print(newDate); // 01/25/2023 12:37 AM
var date = '2023-01-25T00:37:00.000Z';
var parsedDate = DateFormat('yyyy-MM-ddTHH:mm:ss').parse(date);
var finalDate = DateFormat("MMM dd").format(parsedDate);
var finalTime = DateFormat.jm().format(parsedDate);
var allDate = DateFormat("MMM dd hh:mm a").format(parsedDate);
print("finalDate = $finalDate"); // Jan 25
print("finalTime = $finalTime"); // 12:37 AM
print("allDate = $allDate"); // Jan 25 12:37 AM
import 'package:intl/intl.dart';
String dateTimeString = "data.matchScheduleDateTime";
// Parse the date time string using the "dd-MM-y" format
var dateTime = DateFormat("dd-MM-y").parse(dateTimeString);
// Format the date part using the "dd-MM-y" format
var dateFormat = DateFormat("dd-MM-y").format(dateTime);
// Format the time part using the "jm" format (j for 12-hour format and m for minutes)
var timeFormat = DateFormat("jm").format(dateTime);
// Format the am/pm part
var amPmFormat = DateFormat("a").format(dateTime);
print("Date: $dateFormat Time: $timeFormat $amPmFormat");
3条答案
按热度按时间kxxlusnw1#
您需要使用
DateTime
解析它并使用DateFormat
转换它:j9per5c42#
可以像这样使用
DateFormat
:bpzcxfmw3#