GithubHelp home page GithubHelp logo

vishhmakasana / get-time-ago Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nixrajput/get-time-ago

0.0 0.0 0.0 1022 KB

A Flutter package to convert and format DateTime object into get_time_ago format to get String like 10 seconds ago, a minute ago, 7 hours ago, etc.

License: BSD 3-Clause "New" or "Revised" License

Dart 92.69% Kotlin 1.14% Swift 1.77% Objective-C 0.17% HTML 4.23%

get-time-ago's Introduction

get_time_ago

A Flutter package to convert and format DateTime object into get_time_ago format to get
String like 10 seconds ago, a minute ago, 7 hours ago, etc.

pub package CI

Installation

Add get_time_ago as a dependency in your pubspec.yaml file.

dependencies:
  get_time_ago: ^1.0.9

Usage

Format any DateTime object into get_time_ago format by following steps:

// Import the plugin
import 'package:get_time_ago/get_time_ago.dart';

// Pass DateTime object as argument in the method
var _dateTime = DateTime.now().subtract(const Duration(minutes: 10)); // [DateTime] object
print(GetTimeAgo.parse(_dateTime)); // 10 minutes ago

// Formatting with locale
print(GetTimeAgo.parse(_dateTime, locale:'es')); // hace 10 minutos

Formatting String as get_time_ago

If you have saved a DateTime object as a String into a variable, database or cloud, then you have to first convert the String into DateTime object and then pass it as argument in parse method of get_time_ago plugin to format it into get_time_ago format by following steps:

// Import the plugin
import 'package:get_time_ago/get_time_ago.dart';

var _timestamp = '2021-05-10 05:21:37.712498'; // [DateTime] formatted as String.
var _convertedTimestamp = DateTime.parse(_timestamp); // Converting into [DateTime] object
var result = GetTimeAgo.parse(_convertedTimestamp); 
print(result);

Setting default locale

If you want to change your default locale, then call setDefaultLocale method and pass the locale code as the argument.

// Import the plugin
import 'package:get_time_ago/get_time_ago.dart';

@override
  void initState() {
    super.initState();
    GetTimeAgo.setDefaultLocale('fr'); // Sets the default locale to French
  }

Migrating to 1.0.3+

Starting with version 1.0.3 of the get_time_ago plugin, the default class name has been changed from TimeAgo to GetTimeAgo and method getTimeAgo has been renamed to parse to make the method call easy and reduce the confusion around class name and method name. It is recommended to migrate from old version to new version for seamless and efficient performance.

Changes regarding the mew method call

Old API New API
TimeAgo.getTimeAgo(...) GetTimeAgo.parse(...)

Screenshots

Screenshot_1 Screenshot_2

Connect With Me

nixrajput | Website

nixrajput | GitHub

nixrajput | Instagram

nixrajput | Facebook

nixrajput | Twitter

nixrajput | LinkedIn

get-time-ago's People

Contributors

nixrajput avatar mejans avatar melodysdreamj avatar kidozh avatar ywake avatar vishhmakasana avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.