skip to Main Content

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"
   ),
)

2

Answers


  1. Chosen as BEST ANSWER

    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"
       ),
    )
    

  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search