Description
This library is a package of functions that let you manipulate objects and or java date string. it combine the most common functions used when managing dates under android, such as converting a mysql /sqlLite date to a Date object and vis-versa etc.
This library is available under the MIT License.
DateTimeUtils alternatives and similar packages
Based on the "Utility" category.
Alternatively, view DateTimeUtils alternatives based on common mentions on social networks and blogs.
-
StatusBarUtil
A util for setting status bar style on Android App. -
timber
A logger with a small, extensible API which provides utility on top of Android's normal Log class. -
ExpirableDiskLruCache
Java implementation of a Disk-based LRU cache which specifically targets Android compatibility. -
Byte Buddy
Runtime code generation for the Java virtual machine. -
tape
A lightning fast, transactional, file-based FIFO for Android and Java. -
joda-time-android
Joda-Time library with Android specialization -
tray
a SharedPreferences replacement for Android with multiprocess support -
OpenKeychain
OpenKeychain is an OpenPGP implementation for Android. -
AutobahnAndroid
WebSocket & WAMP in Java for Android and Java 8 -
easydeviceinfo
:iphone: [Android Library] Get device information in a super easy way. -
Android-Templates-And-Utilities
Collection of source codes, utilities, templates and snippets for Android development. -
secure-preferences
Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure. -
greenrobot-common
General purpose utilities and hash functions for Android and Java (aka java-common) -
Androl4b
A Virtual Machine For Assessing Android applications, Reverse Engineering and Malware Analysis -
vector-compat
A support library for VectorDrawable and AnimatedVectorDrawable classes introduced in Lollipop -
CastCompanionLibrary-android
CastCompanionLibrary-android is a library project to enable developers integrate Cast capabilities into their applications faster and easier. -
android_dbinspector
Android library for viewing, editing and sharing in app databases. -
AndroidBillingLibrary
Android Market In-app Billing Library -
motion
An Android library allowing images to exhibit a parallax effect that reacts to the device's tilt -
Colours
A beautiful set of predefined colors and a set of color methods to make your Android development life easier. -
EasyCamera
Wrapper around the android Camera class that simplifies its usage -
MrVector
[Deprecated] AKA VectorDrawableCompat: A 7+ backport of VectorDrawable -
Reservoir
Android library to easily serialize and cache your objects to disk using key/value pairs. -
davdroid
DAVdroid – CalDAV/CardDAV synchronization for Android 4+ devices -
android-validation-komensky
A simple library for validating user input in forms using annotations. -
dspec
A simple way to define and render UI specs on top of your Android UI. -
routable-android
Routable, an in-app native URL router, for Android -
Treasure
Very easy to use wrapper library for Android SharePreferences -
RoboGif
A small utility to record Android device screen to a GIF
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of DateTimeUtils or a related project?
README
DateTimeUtils
This library is a package of functions that let you manipulate objects and or java date string. it combine the most common functions used when managing dates under android, such as converting a mysql /sqlLite date to a Date object and vis-versa etc.
This library is available under the MIT License.
Usage
The DateTimeUtils library is available from JitPack.
First add JitPack dependency line in your project build.gradle
file:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
And then simply add the following line to the dependencies
section of your app module build.gradle
file:
implementation 'com.github.thunder413:DateTimeUtils:3.0'
Javadocs are available here.
Examples
setTimeZone
setTimeZone
allow you to define your time zone by default it's UTC
DateTimeUtils.setTimeZone("UTC");
formatDate
formatDate
is a method that allow you to convert date object
to string
or timeStamp
to date and vice-versa.
Date string to Date object
// MySQL/SQLite dateTime example
Date date = DateTimeUtils.formatDate("2017-06-13 04:14:49");
// Or also with / separator
Date date = DateTimeUtils.formatDate("2017/06/13 04:14:49");
// MySQL/SQLite date example
Date date = DateTimeUtils.formatDate("2017-06-13");
// Or also with / separator
Date date = DateTimeUtils.formatDate("2017/06/13");
Date object to date string MySQL/SQLite
String date = DateTimeUtils.formatDate(new Date());
timeStamp to Date object
By default it will considere given timeStamp in milliseconds but in case you did retrieve the timeStamp from server wich usually will be in seconds supply DateTimeUnits.SECONDS
to tell the fonction about
// Using milliseconds
Date date = DateTimeUtils.formatDate(1497399731000);
// Using seconds (Server timeStamp)
Date date = DateTimeUtils.formatDate(1497399731,DateTimeUnits.SECONDS);
formatWithStyle
formatWithStyle
allow to parse date into localized format using most common style
Date object to localized date
DateTimeUtils.formatWithStyle(new Date(), DateTimeStyle.FULL); // Tuesday, June 13, 2017
DateTimeUtils.formatWithStyle(new Date(), DateTimeStyle.LONG); // June 13, 2017
DateTimeUtils.formatWithStyle(new Date(), DateTimeStyle.MEDIUM); // Jun 13, 2017
DateTimeUtils.formatWithStyle(new Date(), DateTimeStyle.SHORT); // 06/13/17
Date string to localized date
DateTimeUtils.formatWithStyle("2017-06-13", DateTimeStyle.FULL); // Tuesday, June 13, 2017
DateTimeUtils.formatWithStyle("2017-06-13", DateTimeStyle.LONG); // June 13, 2017
DateTimeUtils.formatWithStyle("2017-06-13", DateTimeStyle.MEDIUM); // Jun 13, 2017
DateTimeUtils.formatWithStyle("2017-06-13", DateTimeStyle.SHORT); // 06/13/17
formatWithPattern
formatWithPattern
allow to define your own parse pattern following SimpleDateFormat
scheme
Date string as source
DateTimeUtils.formatWithPattern("2017-06-13", "EEEE, MMMM dd, yyyy"); // Tuesday, June 13, 2017
Date object as source
DateTimeUtils.formatWithPattern(new Date(), "EEEE, MMMM dd, yyyy"); // Tuesday, June 13, 2017
### isToday
isToday
Tell whether or not a given date is today date
// Date object as source
boolean state = DateTimeUtils.isToday(new Date());
// Date String as source
boolean state = DateTimeUtils.isToday("2017-06-15 04:14:49");
isYesterday
isYesterday
Tell whether or not a given date is yesterday date
// Date object as source
boolean state = DateTimeUtils.isYesterday(new Date());
// Date String as source
boolean state = DateTimeUtils.isYestrday("2017-06-15 04:14:49");
Get Previous next Week
getPreviousWeekDate/getNextWeekDate
Return the next or a previous week date from a given date it also allow you to set the day of the week by using Calendar Constant
// Date object as source
Date date = DateTimeUtils.getPreviousWeekDate(new Date(), Calendar.MONDAY);
// Date String as source
Date date = DateTimeUtils.getNextWeekDate("2017-06-15 04:14:49",Calendar.SUNDAY);
Get Previous next month
getPreviousMonthDate/getNextMonthDate
Return the next or a previous month date from a given date
// Date object as source
Date date = DateTimeUtils.getNextMonthDate(new Date());
// Date String as source
Date date = DateTimeUtils.getPreviousMonthDate("2017-06-15 04:14:49");
getDateDiff
getDateDiff
give you the difference between two date in days, hours, minutes, seconds or milliseconds DateTimeUnits
// Dates can be date object or date string
Date date = new Date();
String date2 = "2017-06-13 04:14:49";
// Get difference in milliseconds
int diff = DateTimeUtils.getDateDiff(date,date2, DateTimeUnits.MILLISECONDS);
// Get difference in seconds
int diff = DateTimeUtils.getDateDiff(date,date2, DateTimeUnits.SECONDS);
// Get difference in minutes
int diff = DateTimeUtils.getDateDiff(date,date2, DateTimeUnits.MINUTES);
// Get difference in hours
int diff = DateTimeUtils.getDateDiff(date,date2, DateTimeUnits.HOURS);
// Get difference in days
int diff = DateTimeUtils.getDateDiff(date,date2, DateTimeUnits.DAYS);
getTimeAgo
getTimeAgo
give ou the elapsed time since a given date, it also offer two print mode the full and short strings eg . 3 hours ago | 3h ago
the strings are localized but at the moment only FR and EN language are available. If you need your langage to be add just let me know :)
String timeAgo = DateTimeUtils.getTimeAgo(context,new Date()); // Full string style will be used
// Short string style
String timeAgo = DateTimeUtils.getTimeAgo(context,"new Date()",DateTimeStyle.AGO_SHORT_STRING );
formatTime
formatTime
allow you to extract time from date by default it wont show the hours if equal to 0
but you can supply forceShowHours
parameter to force hours display
String time = DateTimeUtils.formatTime(new Date()); // 14:49 if hours equals 0 or 04:14:09 if hours witch is wrong when use it on time rather than a duration
// Solution >> force hours display
String time = DateTimeUtils.formatTime(new Date(),true);
// And you can also supplie a date string
String time = DateTimeUtils.formatTime("2017-06-13 04:14:49"); // 04:14:49
millisToTime
millisToTime
is usefull when your dealing with duration and want to display for example player duration or current playback position into human readable value.
String time = DateTimeUtils.millisToTime(2515); // It take millis as an argument not seconds
timeToMillis
timeToMillis
allow to convert time
string to millseconds
int milliseconds = DateTimeUtils.timeToMillis("14:20"); // 860000
Author
- Thunder413 (https://github.com/thunder413)
License
This project is licensed under the MIT License
*Note that all licence references and agreements mentioned in the DateTimeUtils README section above
are relevant to that project's source code only.