Home > Enterprise >  How to transform DateTime to local time in intl?
How to transform DateTime to local time in intl?

Time:12-06

I have an intl and I want to show local time(15:15, 16:27) but intl shows me 03:16 AM and so on. How can I transfer time to local time?

This is my code:

Text(
   DateFormat('hh:mm').format(trackballDetails.point!.x),
   style: TextStyle(
      color: Colors.white,
      fontSize: 10.sp,
      fontFamily: "Mont"
   ),
)

CodePudding user response:

Try below code just set format like HH:mm :

import 'package:intl/intl.dart';

void main() {
  var dateFormate = DateFormat("dd-MM-yyyy HH:mm a")
      .format(DateTime.parse("2022-09-30 15:15"));
  print(dateFormate);
}

Output-> 30-09-2022 15:15 PM

Result Screen-> image

CodePudding user response:

If you meet the same problem, try this:

var tag = Localizations.maybeLocaleOf(context)?.toLanguageTag();


Text(
   DateFormat.Hm(tag).format(trackballDetails.point!.x),
   style: TextStyle(
      color: Colors.white,
      fontSize: 10.sp,
      fontFamily: "Mont"
   ),
)

CodePudding user response:

DateFormat('hh:mm').format(trackballDetails.point!.x).toLocal();

  • Related