Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final int DAY = 1; public static final int NIGHT = 2; public static int isDayorNight() { SimpleDateFormat sdf = new SimpleDateFormat("HH"); String hour = sdf.format(new Date()); int k = Integer.parseInt(hour); if ((k >= 0 && k < 6) || (k >= 18 && k < 24)) { return NIGHT; } else { return DAY; } } }