Android Open Source - eclipse-ui-tips Time






From Project

Back to project page eclipse-ui-tips.

License

The source code is released under:

Eclipse Public License -v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUT...

If you think the Android project eclipse-ui-tips listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright (c) 2012 Kaloyan Raev./*ww  w  .  j  a  va  2 s .  c o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Kaloyan Raev - initial implementation
 *******************************************************************************/
package name.raev.kaloyan.android.eclipseuitips;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.util.Log;

public class Time {
  
  public static final String DEFAULT = "08:30";
  public static final String FORMAT = "HH:mm";
  
  private String value;
  private SimpleDateFormat dfm = new SimpleDateFormat(FORMAT);
  
  public Time() {
    this(DEFAULT);
  }
  
  public Time(String value) {
    this.value = value;
  }
  
  public Time(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    
    this.value = dfm.format(calendar.getTime());
  }
  
  public int getHour() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(toDate());
    return calendar.get(Calendar.HOUR_OF_DAY);
  }
  
  public int getMinute() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(toDate());
    return calendar.get(Calendar.MINUTE);
  }
  
  public Date toDate() {
    try {
      return dfm.parse(value);
    } catch (ParseException e) {
      Log.e(Time.class.getName(), "Error parsing time value", e);
      // return the current time
      return new Date();
    }
  }

  @Override
  public String toString() {
    return value;
  }
  
}




Java Source Code List

name.raev.kaloyan.android.eclipseuitips.AlarmReceiver.java
name.raev.kaloyan.android.eclipseuitips.BootCompletedReceiver.java
name.raev.kaloyan.android.eclipseuitips.BrowseAllGuidelinesPreference.java
name.raev.kaloyan.android.eclipseuitips.CategoriesActivity.java
name.raev.kaloyan.android.eclipseuitips.CategoriesFragment.java
name.raev.kaloyan.android.eclipseuitips.GuidelinesFragment.java
name.raev.kaloyan.android.eclipseuitips.GuidelinesPagerActivity.java
name.raev.kaloyan.android.eclipseuitips.OpenRandomGuidelinePreference.java
name.raev.kaloyan.android.eclipseuitips.OpenUrlPreference.java
name.raev.kaloyan.android.eclipseuitips.Preferences.java
name.raev.kaloyan.android.eclipseuitips.Scheduler.java
name.raev.kaloyan.android.eclipseuitips.TimePreference.java
name.raev.kaloyan.android.eclipseuitips.Time.java
name.raev.kaloyan.android.eclipseuitips.UpNavigationActivity.java
name.raev.kaloyan.android.eclipseuitips.WelcomeActivity.java
name.raev.kaloyan.android.eclipseuitips.model.Category.java
name.raev.kaloyan.android.eclipseuitips.model.Guideline.java
name.raev.kaloyan.android.eclipseuitips.model.Subcategory.java