我想将字符串(12 小时)“6:45PM”转换为 18:45:00(24 小时)TimeOfDay 格式,这怎么做?
Tin*_*son 14
您可以尝试使用 DateFormat,只需在 pubspec.yaml 中包含 intl 依赖项
首先将值解析为日期,然后根据需要对其进行格式化
import 'package:intl/intl.dart';
// parse date
DateTime date= DateFormat.jm().parse("6:45 PM");
DateTime date2= DateFormat("hh:mma").parse("6:45PM"); // think this will work better for you
// format date
print(DateFormat("HH:mm").format(date));
print(DateFormat("HH:mm").format(date2));
Run Code Online (Sandbox Code Playgroud)
参考
小智 6
尝试这个:
var df = DateFormat("h:mma");
var dt = df.parse('6:45PM');
print(DateFormat('HH:mm').format(dt));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4478 次 |
| 最近记录: |