Skip to content

Commit a5bd0d8

Browse files
committed
Add htime example.
1 parent a49b9ae commit a5bd0d8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.cronutils.example;
2+
3+
import com.cronutils.htime.HDateTimeFormatBuilder;
4+
import org.joda.time.DateTime;
5+
import org.joda.time.format.DateTimeFormatter;
6+
7+
import java.text.SimpleDateFormat;
8+
import java.util.Date;
9+
import java.util.Locale;
10+
11+
public class HTimeExamples {
12+
public static void main(String[] args) {
13+
//You no longer need to remember "YYYY-MM-dd KK a" patterns.
14+
//we can create a formatter for JodaTime
15+
DateTimeFormatter jodatimeFormatter = HDateTimeFormatBuilder.getInstance().forJodaTime().getFormatter(Locale.US).forPattern("June 9, 2011");
16+
System.out.println(jodatimeFormatter.print(DateTime.now()));//formattedDateTime will be lastExecution in "dayOfWeek, Month day, Year" format
17+
18+
//or we can create a formatter for JDK time
19+
SimpleDateFormat jdkFormatter = HDateTimeFormatBuilder.getInstance().forJDK12().getFormatter(Locale.US).forPattern("June 9, 2011");
20+
System.out.println(jdkFormatter.format(new Date()));//formattedDateTime will be lastExecution in "dayOfWeek, Month day, Year" format
21+
}
22+
}

0 commit comments

Comments
 (0)