SimpleDate is a Kotlin Library which helps you format the date as per your requirement.
In project-level build.gradle
:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.sidhuparas:SimpleDate:<latest-version>'
}
SimpleDate
uses Kotlin Extension Functions since Version 2.0. This makes it incompatible with the older versions of the library. But thanks to extension functions, the API looks very clean on Kotlin as well as Java.
You can use the methods on a date object. Following are the available functions:
date
.toDateTimeStandard() // 13 August 2019 21:55:11
.toDateTimeStandardIn12Hours() // 13 August 2019 9:55:11 PM
.toDateTimeStandardInDigits() // 13-08-2019 21:55:11
.toDateTimeStandardInDigitsAnd12Hours() // 13-08-2019 9:55:11 PM
.toDateTimeStandardConcise() // 13 Aug 2019 21:55:11
.toDateTimeStandardConciseIn12Hours() // 13 Aug 2019 9:55:11 PM
.toDateTimeYY() // 13 August 19 21:55:11
.toDateTimeYYIn12Hours() // 13 August 19 9:55:11 PM
.toDateTimeYYInDigits() // 13-08-19 21:55:11
.toDateTimeYYInDigitsAnd12Hours() // 13-08-19 9:55:11 PM
.toDateTimeYYConcise() // 13 Aug 19 21:55:11
.toDateTimeYYConciseIn12Hours() // 13 Aug 19 9:55:11 PM
.toZuluFormat() // 2019-08-19T21:16:55:11.926Z
date
.toTimeStandard() // 21:55:11
.toTimeStandardWithoutSeconds() // 21:55
.toTimeStandardIn12Hours() // 9:55:11 PM
.toTimeStandardIn12HoursWithoutSeconds() // 9:55 PM
date
.toDateStandard() // 13 August 2019
.toDateStandardConcise() // 13 Aug 2019
.toDateStandardInDigits() // 13-08-2019
.toDateYY() // 13 August 19
.toDateYYConcise() // 13 Aug 19
.toDateYYInDigits() // 13-08-19
.toDateYMD() // 2019 August 13
.toDateYMDConcise() // 2019 Aug 13
.toDateYMDInDigits() // 2019-08-13
.toDateEMd() // Tue, Aug 13
.toDateEMYShort() // Tue, Aug 19
.toDateEMY() // Tuesday, August 2019
date.toDay() // Tuesday
- Kotlin:
val date = Date()
println(date.toDateTimeStandard())
- Java:
Date date = new Date();
System.out.println(SimpleDateKt.toDateTimeStandard(date));
- Fork the repo
- Create a new branch and make changes
- Push the code to the branch and make a PR! 👍