finap_datetime_helper 0.0.3 copy "finap_datetime_helper: ^0.0.3" to clipboard
finap_datetime_helper: ^0.0.3 copied to clipboard

Flutter date time helper.

Finap Datetime Helper

Features #

Utility functions for Date Time

Getting started #

Run this command to install

flutter pub add finap_datetime_helper

Usage #

Get now as Miliseconds #

static int getNowFromMilliseconds() {
    try {
      return DateTime.now().toUtc().millisecondsSinceEpoch;
    } on Exception catch (e) {
      print(e.toString());
      return 0;
    }
  }

get Date time from miliseconds #

static DateTime? getDate(int miliseconds) {
    try {
      return DateTime.fromMillisecondsSinceEpoch(miliseconds, isUtc: true);
    } on Exception catch (e) {
      print(e.toString());
      return null;
    }
  }

get string date from miliseconds #

static String? getDateString(int? miliseconds) {
    final formatter = DateFormat('dd-MMM-yyyy hh:mm a');
    if (miliseconds == null) return '';
    final date = getDate(miliseconds);
    if (date != null) {
      return formatter.format(date.toLocal());
    }
    return '';
  }

get Date in seconds #

static String? getDateInSecondsString(int? seconds) {
    final formatter = DateFormat('dd-MMM-yyyy hh:mm a');
    if (seconds == null) return '';
    final date = getDate(seconds * 1000);
    if (date != null) {
      return formatter.format(date.toLocal());
    }
    return '';
  }

get Only date string by providing miliseconds #

static String? getOnlyDateString(int? miliseconds) {
    final formatter = DateFormat('dd-MMM-yyyy');
    if (miliseconds == null) return '';
    final date = getDate(miliseconds);
    if (date != null) {
      return formatter.format(date.toLocal());
    }
    return '';
  }
0
likes
100
pub points
13%
popularity

Publisher

unverified uploader

Flutter date time helper.

Homepage

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, intl

More

Packages that depend on finap_datetime_helper