Skip to content

Instantly share code, notes, and snippets.

Created September 29, 2016 15:25
Show Gist options
  • Save anonymous/55a98bbdb9b5eb3eeaee5f8984f11687 to your computer and use it in GitHub Desktop.
Save anonymous/55a98bbdb9b5eb3eeaee5f8984f11687 to your computer and use it in GitHub Desktop.
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