fromString static method

String fromString(
  1. String time, {
  2. String format = 'yyyy-MM-dd hh:mm:ss',
  3. TimeUnit timeUnit = TimeUnit.millisecond,
})

Get the specified format time string from the string timestamp. time Timestamp to be processed. format Format time string. timeUnit The unit of the timestamp to be processed.

Implementation

static String fromString(
  String time, {
  String format = 'yyyy-MM-dd hh:mm:ss',
  TimeUnit timeUnit = TimeUnit.millisecond,
}) {
  final int? timeValue = int.tryParse(time);
  assert(timeValue != null,
      'Invalid time string.Please check whether the string is all numbers.');
  late IDKitTimeFormat idkitTimeFormat = IDKitTimeFormat();
  final DateTime dateTime = idkitTimeFormat.dateFromInt(timeValue!, timeUnit);
  return idkitTimeFormat.stringFrom(dateTime, format);
}