Java Code Examples for java.util.Date.getHours()

The following are Jave code examples for showing how to use getHours() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: stynico   File: DateUtil.java   View Source Code Vote up 6 votes
/**
 * 获取友好时间表示
 * @param s
 * @return
 */
public static String getFriendlyDate(String s){
    Date old=toDate(s);
    Date nowTime=new Date(System.currentTimeMillis());
    long values=nowTime.getTime()-old.getTime();
    values/=1000;
    if(values>=0&&values<60){
        return values+"秒前";
    }
    if(values>=60&&values<60*60){
        return values/60+"分钟前";
    }
    if(values>=60*60&&values<60*60*24){
        return values/3600+"小时前";
    }
    if(values>=60*60*24&&values<60*60*24*2){
        return "昨天:"+old.getHours()+":"+old.getTime();
    }
    if(values>=60*60*24*2&&values<60*60*24*3){
        return "前天:"+old.getHours()+":"+old.getTime();
    }
    return s;
}
 
Example 2
Project: mobile-store   File: ZioEntry.java   View Source Code Vote up 6 votes
public void setTime(long time) {
    Date d = new Date(time);
    long dtime;
    int year = d.getYear() + 1900;
    if (year < 1980) {
        dtime = (1 << 21) | (1 << 16);
    }
    else {
        dtime = (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
        d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
        d.getSeconds() >> 1;
    }

    modificationDate = (short)(dtime >> 16);
    modificationTime = (short)(dtime & 0xFFFF);
}
 
Example 3
Project: myfaces-trinidad   File: DateTimeConverterTestCase.java   View Source Code Vote up 6 votes
/**
 * @todo have to solve the milli second problem that which is there.!!
 * @param convDate
 * @param expectedDate
 * @return
 */
@SuppressWarnings("deprecation")
protected static boolean isEqual(Date convDate, Date expectedDate)
{
  GregorianCalendar convGcal = new GregorianCalendar();
  convGcal.setTime(convDate);

  GregorianCalendar expGcal = new GregorianCalendar();
  expGcal.setTime(expectedDate);

  // -= Simon Lessard =-
  // FIXME: Switch to Calendar methods
  return
    (convDate.getSeconds() == expectedDate.getSeconds()) &&
    (convDate.getYear()    == expectedDate.getYear())    &&
    (convDate.getMonth()   == expectedDate.getMonth())   &&
    (convDate.getDate()    == expectedDate.getDate())    &&
    (convDate.getHours()   == expectedDate.getHours())   &&
    (convDate.getMinutes() == expectedDate.getMinutes()) ;
}
 
Example 4
Project: amap   File: MIP_DateUtil.java   View Source Code Vote up 6 votes
@SuppressWarnings("deprecation")
public static boolean isBetweenTime(int startHour, int startMin, int endHour, int endMin)
{
    Date cD = getCurrentDate();
    int hour = cD.getHours();
    int min = cD.getMinutes();
    
    long cTime = hour * 60 + min;
    
    long startTime = startHour * 60 + startMin;
    long endTime = endHour * 60 + endMin;
    if (cTime > startTime && cTime < endTime)
    {
        return true;
    }
    return false;
}
 
Example 5
Project: buildAPKsSamples   File: ClockActivity.java   View Source Code Vote up 6 votes
private void setTime() {
  Date now = new Date();
  int hours = now.getHours();
  hours = (hours>12)?hours-12:hours;
  int minutes  = now.getMinutes();
  int h1 = hours/10;
  int h2 = hours - h1*10;
  int m1 = minutes/10;
  int m2 = minutes -  m1*10;
  
  Log.d(TAG, String.format("%d:%d -> %d %d: %d %d",hours, minutes, h1, h2, m1, m2));
  
  h1View.setImageResource( numToRes(h1) );
  h2View.setImageResource( numToRes(h2) );
  m1View.setImageResource( numToRes(m1) );
  m2View.setImageResource( numToRes(m2) );
}
 
Example 6
Project: NotifyTools   File: CalcLunar.java   View Source Code Vote up 5 votes
public String GetChineseHour(Date dt, Date _date) {

        int _hour, offset, i;
        int _minute = 0;
        int indexGan;
        String ganHour, zhiHour;
        String tmpGan;

        //计算时辰的地支
        _hour = dt.getHours();   //获得当前时间小时
        _minute = dt.getMinutes();  //获得当前时间分钟

        if (_minute != 0) _hour += 1;
        offset = _hour / 2;
        if (offset >= 12) offset = 0;
        //zhiHour = zhiStr[offset].ToString();

        //计算天干
        int ts = Utils.daysBetween(_date, Consts.GanZhiStartDay);
        i = ts % 60;

        indexGan = ((i % 10 + 1) * 2 - 1) % 10 - 1; //ganStr[i % 10] 为日的天干,(n*2-1) %10得出地支对应,n从1开始
        tmpGan = Consts.ganStr.substring(indexGan) + Consts.ganStr.substring(0, indexGan + 2);//凑齐12位
        //ganHour = ganStr[((i % 10 + 1) * 2 - 1) % 10 - 1].ToString();

        return tmpGan.toCharArray()[offset] + "" + Consts.zhiStr.toCharArray()[offset];

    }
 
Example 7
Project: smile_1.5.0_java7   File: DateFeature.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings("deprecation")
public double[] feature(Date date) {
    double[] x = new double[types.length];
    for (int i = 0; i < types.length; i++)
    switch (types[i]) {
        case YEAR:
            x[i] = 1900 + date.getYear();
            break;
        case MONTH:
            x[i] = date.getMonth();
            break;
        case DAY_OF_MONTH:
            x[i] = date.getDate();
            break;
        case DAY_OF_WEEK:
            x[i] = date.getDay();
            break;
        case HOURS:
            x[i] = date.getHours();
            break;
        case MINUTES:
            x[i] = date.getMinutes();
            break;
        case SECONDS:
            x[i] = date.getSeconds();
            break;
        default:
            throw new IllegalStateException("Unknown date feature type: " + types[i]);
    }
    return x;
}
 
Example 8
Project: PaySim   File: ParameterizedPaySim.java   View Source Code Vote up 5 votes
private void initSimulatorName(){
	Date d = new Date();
	ParameterizedPaySim.simulatorName = "PS_" + (d.getYear() + 1900) + (d.getMonth() + 1)  + d.getDate() + d.getHours() + d.getMinutes()
			+ d.getSeconds() + "_" + this.seed;
	//System.out.println(simulatorName + "\n");
	File f = new File(System.getProperty("user.dir")  +"//outputs//" + ParameterizedPaySim.simulatorName);
	f.mkdir();
}
 
Example 9
Project: AutoCar   File: DateUtils.java   View Source Code Vote up 5 votes
public static boolean isXianXing() {
    boolean limit = false;
    Date date = new Date(System.currentTimeMillis());
    final Calendar ca = Calendar.getInstance();
    ca.setTime(date);
    int w = ca.get(Calendar.DAY_OF_WEEK) - 1;
    if (w == LIMIT && date.getHours() >= 7 && date.getHours() < 20) limit = true;
    return limit;
}
 
Example 10
Project: AutoCar   File: DateUtils.java   View Source Code Vote up 5 votes
public static boolean isBusyTime() {
    boolean limit = false;
    Date date = new Date(System.currentTimeMillis());
    final Calendar ca = Calendar.getInstance();
    ca.setTime(date);
    int w = ca.get(Calendar.DAY_OF_WEEK) - 1;
    if (w >= 1 && w <= 5) {//周一到周五
        if ((date.getHours() >= 7 && date.getHours() < 9) ||
                (date.getHours() >= 17 && date.getHours() < 20)) limit = true;
    }

    return limit;
}
 
Example 11
Project: Programmers   File: Util.java   View Source Code Vote up 5 votes
public static boolean getTimeState(long time) {
    boolean output;

    Date last = new Date(time);
    Date current = new Date(System.currentTimeMillis());

    output = last.getYear() < current.getYear() ||
            last.getMonth() < current.getMonth() ||
            last.getDay() < current.getDay() ||
            last.getHours() < current.getHours() ||
            last.getMinutes() < current.getMinutes();

    return output;
}
 
Example 12
Project: OpenJSharp   File: ZipUtils.java   View Source Code Vote up 5 votes
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 13
Project: OpenJSharp   File: ZipUtils.java   View Source Code Vote up 5 votes
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 14
Project: jdk8u-jdk   File: ZipUtils.java   View Source Code Vote up 5 votes
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 15
Project: jdk8u-jdk   File: ZipUtils.java   View Source Code Vote up 5 votes
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 16
Project: HL4A   File: 时间工具.java   View Source Code Vote up 4 votes
public static Integer 小时(Date $时间) {
		return $时间.getHours();
}
 
Example 17
Project: yaacc-code   File: UpnpClientTest.java   View Source Code Vote up 4 votes
protected void startMusicPlay(UpnpClient upnpClient,
		Device<?, ?, ?> device, boolean background, String instanceId) {
	ContentDirectoryBrowseResult browseResult;
	browseResult = upnpClient.browseSync(device, instanceId);
	List<Item> items = browseResult.getResult().getItems();
	for (Item item : items) {

		Log.d(getClass().getName(), "ParentId: " + item.getParentID());
		Log.d(getClass().getName(), "ItemId: " + item.getId());
		Res resource = item.getFirstResource();
		if (resource == null)
			break;
		Log.d(getClass().getName(), "ImportUri: " + resource.getImportUri());
		Log.d(getClass().getName(), "Duration: " + resource.getDuration());
		Log.d(getClass().getName(),
				"ProtocolInfo: " + resource.getProtocolInfo());
		Log.d(getClass().getName(), "ContentFormat: "
				+ resource.getProtocolInfo().getContentFormat());
		Log.d(getClass().getName(), "Value: " + resource.getValue());
		SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");

		// just for a test
		int millis = 0;
		try {
			Date date = dateFormat.parse(resource.getDuration());
			millis = date.getHours() * 60 * 60 * 1000;
			millis += date.getMinutes() * 60 * 1000;
			millis += date.getSeconds() * 1000;
			assertEquals(date.getTime(), millis);
			Log.d(getClass().getName(),
					"HappyHappy Joy Joy Duration in Millis=" + millis);
			Log.d(getClass().getName(), "Playing: " + item.getTitle());
			if (background) {
				Log.d(getClass().getName(),
						"Starting Background service... ");
				Intent svc = new Intent(getContext(),
						BackgroundMusicService.class);
				svc.setData(Uri.parse(resource.getValue()));
				getContext().startService(svc);
			} else {
				intentView(resource.getProtocolInfo().getContentFormat(),
						Uri.parse(resource.getValue()));
			}
		} catch (ParseException e) {
			Log.d(getClass().getName(), "bad duration format");
			;
		}
		myWait(millis);

	}
}
 
Example 18
Project: iosched-reader   File: TestScheduleHelperAction.java   View Source Code Vote up 4 votes
private String timeStr(long time) {
    Date d = new Date(time);
    return d.getHours()+":"+d.getMinutes();
}
 
Example 19
Project: calendar-component   File: DateConstants.java   View Source Code Vote up 4 votes
public static CalDate toRPCDateTime(Date date) {
    return new CalDate(date.getYear() + 1900, date.getMonth() + 1, date.getDate(),
            new CalTime(date.getHours(), date.getMinutes(), date.getSeconds()));
}
 
Example 20
Project: openjdk-jdk10   File: CompilationStatistics.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
public static void clear(String dumpName) {
    try {
        ConcurrentLinkedDeque<CompilationStatistics> snapshot = list;
        long snapshotZeroTime = zeroTime;

        list = new ConcurrentLinkedDeque<>();
        zeroTime = System.nanoTime();

        Date now = new Date();
        String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes();

        dumpCompilations(snapshot, dumpName, dateString);

        try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) {

            long[] timeSpent = new long[10000];
            int maxTick = 0;
            for (CompilationStatistics stats : snapshot) {
                long start = stats.startTime - snapshotZeroTime;
                long duration = stats.duration;
                if (start < 0) {
                    duration -= -start;
                    start = 0;
                }

                int tick = (int) (start / RESOLUTION);
                long timeLeft = RESOLUTION - (start % RESOLUTION);

                while (tick < timeSpent.length && duration > 0) {
                    if (tick > maxTick) {
                        maxTick = tick;
                    }
                    timeSpent[tick] += Math.min(timeLeft, duration);
                    duration -= timeLeft;
                    tick++;
                    timeLeft = RESOLUTION;
                }
            }
            String timelineName = System.getProperty("stats.timeline.name");
            if (timelineName != null && !timelineName.isEmpty()) {
                out.printf("%s%c", CSVUtil.Escape.escape(timelineName), CSVUtil.SEPARATOR);
            }
            for (int i = 0; i < maxTick; i++) {
                out.printf("%d%c", normalize(timeSpent[i]), CSVUtil.SEPARATOR);
            }
            // print last column
            out.printf("%d", normalize(timeSpent[maxTick]));
            out.println();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}