-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApp.java
More file actions
47 lines (38 loc) · 1.25 KB
/
App.java
File metadata and controls
47 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.github.archarithms;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
public class App
{
public static String convertToTitleCase(final String inpStr) throws Exception
{
if (inpStr == null) {
throw new Exception();
}
String[] words = inpStr.split("[^a-zA-Z0-9]");
for (int i = 0; i < words.length; i++) {
String word = words[i];
String head = word.substring(0, 1);
String tail = word.substring(1);
words[i] = head.toUpperCase() + tail.toLowerCase();
}
return String.join(" ", words);
}
public static String convertUnixToDateString() throws Exception
{
Long seconds = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
return convertUnixToDateString(seconds);
}
public static String convertUnixToDateString(final Long inpUnixSeconds) throws Exception
{
if (inpUnixSeconds == null) {
throw new Exception();
}
LocalDateTime date = LocalDateTime.ofEpochSecond(inpUnixSeconds, 0, ZoneOffset.UTC);
DateTimeFormatter formatter = patternedFormatter();
return date.format(formatter);
}
public static DateTimeFormatter patternedFormatter() {
return DateTimeFormatter.ofPattern("MMMM d, yyyy");
}
}