-
-
Save anonymous/55a98bbdb9b5eb3eeaee5f8984f11687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Calendar; | |
import java.util.GregorianCalendar; | |
import java.util.Date; | |
public class GetPeriod | |
{ | |
public static void main(String[] args) | |
{ | |
Date date = new Date(); // Initializes to now. | |
Calendar calendar = GregorianCalendar.getInstance(); | |
calendar.setTime(date); | |
int hour = calendar.get(Calendar.HOUR_OF_DAY); // Hour in 24h format | |
int minute = calendar.get(Calendar.MINUTE); // Minute of the hour | |
int period = hour*60 + minute/30*30; // Integer division rounds down to nearest 30 | |
System.out.print(period); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment