Skip to content

Commit f95affb

Browse files
committed
1. Added date time utils.
2. Format date to string. 3. Format string to date. 4. Get time from date or dateString. 5. Get time difference. 6. Get is today or is yesterday. 7. Get time ago. 8. Convert milli seconds to time or vice versa. 9. Format Date to dateString into formats like yyyy-MM-dd HH:mm:ss or other.
1 parent db25caf commit f95affb

File tree

7 files changed

+829
-3
lines changed

7 files changed

+829
-3
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ allprojects{
1616
```
1717
dependencies {
1818
...
19-
implementation 'com.github.amitjangid80:multiutillib:v1.0.0'
19+
implementation 'com.github.amitjangid80:multiutillib:v1.1.1'
2020
}
2121
```
2222

@@ -34,6 +34,6 @@ dependencies {
3434
<dependency>
3535
<groupId>com.github.amitjangid80</groupId>
3636
<artifactId>multiutillib</artifactId>
37-
<version>v1.0.0</version>
37+
<version>v1.1.1</version>
3838
</dependency>
3939
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.amit.datetime;
2+
3+
/**
4+
* DateTimeFormat
5+
* Patterns used to parse given date {@link DateTimeUtils} will use those pattern
6+
*
7+
**/
8+
@SuppressWarnings("WeakerAccess")
9+
public class DateTimeFormat
10+
{
11+
/**
12+
* Typical MySqL/SQL dateTime format with dash as separator
13+
*/
14+
public static final String DATE_TIME_PATTERN_1 = "yyyy-MM-dd HH:mm:ss";
15+
16+
/**
17+
* Typical MySqL/SQL dateTime format with slash as separator
18+
*/
19+
public static final String DATE_TIME_PATTERN_2 = "dd/MM/yyyy HH:mm:ss";
20+
21+
public static final String DATE_TIME_PATTERN_3 = "dd-MM-yyyy HH:mm:ss";
22+
23+
/**
24+
* Typical MySqL/SQL date format with dash as separator
25+
*/
26+
public static final String DATE_PATTERN_1 = "yyyy-MM-dd";
27+
28+
/**
29+
* Typical MySqL/SQL date format with slash as separator
30+
*/
31+
public static final String DATE_PATTERN_2 = "dd/MM/yyyy";
32+
33+
public static final String DATE_PATTERN_3 = "dd-MM-yyyy";
34+
35+
/**
36+
* Time format full in 24 hours format
37+
*/
38+
public static final String TIME_PATTERN_1 = "HH:mm:ss";
39+
40+
/**
41+
* Time format with am/pm in 12 hours format
42+
**/
43+
public static final String TIME_PATTERN_2 = "hh:mm a";
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.amit.datetime;
2+
3+
import android.content.Context;
4+
5+
import java.util.Date;
6+
7+
/**
8+
* DateTimeStyle
9+
*
10+
* Defined style for parsing date into string used by {@link DateTimeUtils#formatWithStyle(Date, DateTimeStyle)}}
11+
* and also {@link DateTimeUtils#getTimeAgo(Context, Date, DateTimeStyle)}
12+
*
13+
**/
14+
public enum DateTimeStyle
15+
{
16+
/**
17+
* Style full e.g Tuesday, June 13, 2017
18+
*/
19+
FULL,
20+
21+
/**
22+
* Style long e.g June 13, 2017
23+
*/
24+
LONG,
25+
26+
/**
27+
* Style medium e.g Jun 13, 2017
28+
*/
29+
MEDIUM,
30+
31+
/**
32+
* Style short e.g 06/13/17
33+
*/
34+
SHORT,
35+
36+
/**
37+
* Style for ago time e.g 3h ago
38+
*/
39+
AGO_SHORT_STRING,
40+
41+
/**
42+
* Style for ago time e.g 3 hours ago
43+
*/
44+
AGO_FULL_STRING
45+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.amit.datetime;
2+
3+
/**
4+
* DateTimeUnits
5+
* Define units used by {@link DateTimeUtils#getDateDiff(Date, Date, DateTimeUnits)}
6+
* and also {@link DateTimeUtils#formatDate(long, DateTimeUnits)}
7+
*
8+
**/
9+
@SuppressWarnings("WeakerAccess")
10+
public enum DateTimeUnits
11+
{
12+
/**
13+
* Days
14+
*/
15+
DAYS,
16+
17+
/**
18+
* Hours
19+
*/
20+
HOURS,
21+
22+
/**
23+
* Minutes
24+
*/
25+
MINUTES,
26+
27+
/**
28+
* Seconds
29+
*/
30+
SECONDS,
31+
32+
/**
33+
* Milliseconds
34+
*/
35+
MILLISECONDS,
36+
}

0 commit comments

Comments
 (0)