How to remove offset in datetime

Viewed 124

i would like some help on this i actually use TZDateTime and also with specific location now i would to remove the end of the result like .123436+100 from it

final dateTime = TZDateTime.now(getLocation(box.read(timezone)));

the result always i get is something like this

 2022-04-20 17:42:05.032173+1000

but i want is only like this

2022-04-20 17:42:05

how can i remove that actually

1 Answers

I haven't used TZDateTime before but I think it's the same as DateTime. By using DateFormat from intl you can format the string as you want.

ps1: in case TZDateTime cant parse directly, you can turn it to string and pass to DateTime.parse. ps2: this answer of mine is an idea and has not been tested correctly, sorry if it didn't help you.

import 'package:intl/intl.dart';

void main() {
  var time = DateTime.parse('2022-04-20 17:42:05.032173+1000');
  var fm = DateFormat('yyyy-MM-dd hh:mm:ss');
  print(fm.format(time)); // -> 2022-04-20 07:42:05
}

enter image description here

Related