getMilliseconds static method
int
getMilliseconds(
{ - String formartDate = "1970-10-01 00:00:00",
})
Implementation
static int getMilliseconds({String formartDate = "1970-10-01 00:00:00"}) {
formartDate.replaceAll("T", " ");
/// 年必须大于1970年
String mYear = formartDate.substring(0, 4);
if (int.parse(mYear) < 1970) {
mYear = "1970";
}
var result;
try {
result = mYear +
"-" +
formartDate.substring(5, 7) +
"-" +
formartDate.substring(8, 10);
if (formartDate.toString().length >= 13 &&
formartDate.substring(10, 13).isNotEmpty) {
result += "" + formartDate.substring(10, 13);
}
if (formartDate.toString().length >= 17 &&
formartDate.toString().substring(14, 16).isNotEmpty) {
result += ":" + formartDate.substring(14, 16);
}
if (formartDate.toString().length >= 19 &&
formartDate.substring(17, 19).isNotEmpty) {
result += ":" + formartDate.substring(17, 19);
}
print(result);
var dateTime = DateTime.parse(result);
return dateTime.millisecondsSinceEpoch;
} catch (e) {
throw e;
}
}