API time Format with Custom Function By Tahir Alvi

If you want to convert API JSON timestamp to normal time format, just like  "created_at": "2022-12-12T10:13:31.848073Z", to 12/12/2022 10:54 AM first, create a custom Function name (formatDateTime) return type is String then create one Argument name is (date) Type String then simply paste this code [image.png]

 

import 'dart:convert';
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '../../flutter_flow/lat_lng.dart';
import '../../flutter_flow/place.dart';
import '../../flutter_flow/custom_functions.dart';

String formatDateTime(String date) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  // Format Date/Time from API
  DateTime parseDate = DateTime.parse(date);
  DateFormat format = DateFormat('MM/dd/yyyy hh:mm a');
  String formatedDate = format.format(parseDate);
  return formatedDate;

  /// MODIFY CODE ONLY ABOVE THIS LINE
}
 

OutPUt [image.png] Thanks then 

1
1 reply