timeStampToString static method

String timeStampToString(
  1. dynamic timestamp,
  2. dynamic format
)

时间戳转换格式

Implementation

static String timeStampToString(timestamp, format) {
  assert(timestamp != null);

  int time = 0;

  if (timestamp is int) {
    time = timestamp;
  } else {
    time = int.parse(timestamp.toString());
  }

  if (format == null) {
    format = 'yyyy-MM-dd HH:mm:ss';
  }

  DateFormat dateFormat = new DateFormat(format);

  var date = new DateTime.fromMillisecondsSinceEpoch(time);

  return dateFormat.format(date);
}