Home > OS >  How to split the string based on particulat charactor in Dart | Flutter
How to split the string based on particulat charactor in Dart | Flutter

Time:01-01

I'am getting a timestamp 2022-01-01T09:38:28.807 00:00 from the api. I want to split it into date and time. Here from this timestamp i want to split it into 2 from T. for eg from this iam expecting the output. String date = 2022-01-01 and String time =09:38:28.807 00:00. Based on that T charactor i want to split it into two. How to acheive this.

CodePudding user response:

 String _date_and_time = "2022-01-01T09:38:28.807 00:00";

 String date = _date_and_time.split("T")[0];
 String time = _date_and_time.split("T")[1];

 print("Date is : ${date}");
 print("Time is : ${time}"); 

Output

Date is : 2022-01-01

Time is : 09:38:28.807 00:00

  • Related