當前位置: 首頁>>代碼示例>>Java>>正文


Java Time類代碼示例

本文整理匯總了Java中android.text.format.Time的典型用法代碼示例。如果您正苦於以下問題:Java Time類的具體用法?Java Time怎麽用?Java Time使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Time類屬於android.text.format包,在下文中一共展示了Time類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dispatchPopulateAccessibilityEvent

import android.text.format.Time; //導入依賴的package包/類
/**
 * Announce the currently-selected time when launched.
 */
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current time will be spoken.
        event.getText().clear();
        Time time = new Time();
        time.hour = getHours();
        time.minute = getMinutes();
        long millis = time.normalize(true);
        int flags = DateUtils.FORMAT_SHOW_TIME;
        if (mIs24HourMode) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        String timeString = DateUtils.formatDateTime(getContext(), millis, flags);
        event.getText().add(timeString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
開發者ID:ttpho,項目名稱:TimePicker,代碼行數:23,代碼來源:RadialPickerLayout.java

示例2: formatTime

import android.text.format.Time; //導入依賴的package包/類
public static String formatTime(Context context, long when) {
	// TODO: DateUtils should make this easier
	Time then = new Time();
	then.set(when);
	Time now = new Time();
	now.setToNow();

	int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL;

	if (then.year != now.year) {
		flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
	} else if (then.yearDay != now.yearDay) {
		flags |= DateUtils.FORMAT_SHOW_DATE;
	} else {
		flags |= DateUtils.FORMAT_SHOW_TIME;
	}

	return DateUtils.formatDateTime(context, when, flags);
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:20,代碼來源:Utils.java

示例3: getDayName

import android.text.format.Time; //導入依賴的package包/類
/**
 * Given a day, returns just the name to use for that day.
 * E.g "today", "tomorrow", "wednesday".
 *
 * @param context Context to use for resource localization
 * @param dateInMillis The date in milliseconds
 * @return
 */
public static String getDayName(Context context, long dateInMillis) {
    // If the date is today, return the localized version of "Today" instead of the actual
    // day name.

    Time t = new Time();
    t.setToNow();
    int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff);
    int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff);
    if (julianDay == currentJulianDay) {
        return context.getString(R.string.today);
    } else if ( julianDay == currentJulianDay +1 ) {
        return context.getString(R.string.tomorrow);
    } else {
        Time time = new Time();
        time.setToNow();
        // Otherwise, the format is just the day of the week (e.g "Wednesday".
        SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE");
        return dayFormat.format(dateInMillis);
    }
}
 
開發者ID:changja88,項目名稱:Udacity_Sunshine,代碼行數:29,代碼來源:Utility.java

示例4: a

import android.text.format.Time; //導入依賴的package包/類
public String a(int i, Thread thread, long j, String str, String str2, Throwable th) {
    long j2 = j % 1000;
    Time time = new Time();
    time.set(j);
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(a(i)).append(LetvUtils.CHARACTER_BACKSLASH).append(time.format("%Y-%m-%d %H:%M:%S")).append('.');
    if (j2 < 10) {
        stringBuilder.append("00");
    } else if (j2 < 100) {
        stringBuilder.append('0');
    }
    stringBuilder.append(j2).append(' ').append('[');
    if (thread == null) {
        stringBuilder.append("N/A");
    } else {
        stringBuilder.append(thread.getName());
    }
    stringBuilder.append(']').append('[').append(str).append(']').append(' ').append(str2).append('\n');
    if (th != null) {
        stringBuilder.append("* Exception : \n").append(Log.getStackTraceString(th)).append('\n');
    }
    return stringBuilder.toString();
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:24,代碼來源:h.java

示例5: updateTime

import android.text.format.Time; //導入依賴的package包/類
private void updateTime() {
	// TODO KIO Is this really necessary to creat a calendar?
	// Calendar calendar = Calendar.getInstance();
	// calendar.setTime(mTest.getDate());

	Log.d(TAG_KIO, "Inside updateTime() mDate time is: "
			+ mTest.getDate().getTime());
	Log.d(TAG_KIO, "Inside updateTime() mDate is: " + mTest.getDate());

	Time time = new Time();
	time.set(mTest.getDate().getTime());

	String timeFormat = time.format("%I:%M");
	Log.d(TAG_KIO, "timeFormat is: " + timeFormat);
	mTimeButton.setText(timeFormat);
}
 
開發者ID:publiclab,項目名稱:SmART-Form,代碼行數:17,代碼來源:TestFragment.java

示例6: formatTime

import android.text.format.Time; //導入依賴的package包/類
static public String formatTime(int ms) {
    String res;
    if (ms <= 0) {
        res = EMPTY_STRING;
    } else {
        Time t = new Time();
        t.set(ms);
        t.switchTimezone(Time.TIMEZONE_UTC);
        if (ms >= 3600000) {
            res = t.format(TIME_HOUR);
        } else if (ms < 60000)
            res = t.format(TIME_SECOND);
        else
            res = t.format(TIME_MINUTE);

        if (res.charAt(0) == '0') {
            res = res.substring(1);
        }
    }
    return res;
}
 
開發者ID:archos-sa,項目名稱:aos-Video,代碼行數:22,代碼來源:Browser.java

示例7: createNdefMessage

import android.text.format.Time; //導入依賴的package包/類
/**
 * Implementation for the CreateNdefMessageCallback interface
 */
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    Time time = new Time();
    time.setToNow();
    String text = ("Beam me up!\n\n" +
            "Beam Time: " + time.format("%H:%M:%S"));
    NdefMessage msg = new NdefMessage(NdefRecord.createMime(
            "application/com.example.android.beam", text.getBytes())
     /**
      * The Android Application Record (AAR) is commented out. When a device
      * receives a push with an AAR in it, the application specified in the AAR
      * is guaranteed to run. The AAR overrides the tag dispatch system.
      * You can add it back in to guarantee that this
      * activity starts when receiving a beamed message. For now, this code
      * uses the tag dispatch system.
      */
      //,NdefRecord.createApplicationRecord("com.example.android.beam")
    );
    return msg;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:24,代碼來源:Beam.java

示例8: a

import android.text.format.Time; //導入依賴的package包/類
public String a(int i, Thread thread, long j, String str, String str2, Throwable th) {
    long j2 = j % 1000;
    Time time = new Time();
    time.set(j);
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(a(i)).append('/').append(time.format("%Y-%m-%d %H:%M:%S")).append('.');
    if (j2 < 10) {
        stringBuilder.append("00");
    } else if (j2 < 100) {
        stringBuilder.append('0');
    }
    stringBuilder.append(j2).append(' ').append('[');
    if (thread == null) {
        stringBuilder.append("N/A");
    } else {
        stringBuilder.append(thread.getName());
    }
    stringBuilder.append(']').append('[').append(str).append(']').append(' ').append(str2)
            .append('\n');
    if (th != null) {
        stringBuilder.append("* Exception : \n").append(Log.getStackTraceString(th)).append
                ('\n');
    }
    return stringBuilder.toString();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:h.java

示例9: parse

import android.text.format.Time; //導入依賴的package包/類
public static long parse(String timeString)
        throws IllegalArgumentException {

    int date = 1;
    int month = Calendar.JANUARY;
    int year = 1970;
    TimeOfDay timeOfDay;

    Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
    if (rfcMatcher.find()) {
        date = getDate(rfcMatcher.group(1));
        month = getMonth(rfcMatcher.group(2));
        year = getYear(rfcMatcher.group(3));
        timeOfDay = getTime(rfcMatcher.group(4));
    } else {
        Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
        if (ansicMatcher.find()) {
            month = getMonth(ansicMatcher.group(1));
            date = getDate(ansicMatcher.group(2));
            timeOfDay = getTime(ansicMatcher.group(3));
            year = getYear(ansicMatcher.group(4));
        } else {
            throw new IllegalArgumentException();
        }
    }

    // FIXME: Y2038 BUG!
    if (year >= 2038) {
        year = 2038;
        month = Calendar.JANUARY;
        date = 1;
    }

    Time time = new Time(Time.TIMEZONE_UTC);
    time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
            month, year);
    return time.toMillis(false /* use isDst */);
}
 
開發者ID:snoozinsquatch,項目名稱:unity-obb-downloader,代碼行數:39,代碼來源:HttpDateTime.java

示例10: formatTime

import android.text.format.Time; //導入依賴的package包/類
public String formatTime(long ms) {
	String res;
	if (ms == 0) {
		res = "";
	} else {
		Time t = new Time();
		t.set(ms);
		t.switchTimezone(Time.TIMEZONE_UTC);
		if (ms >= 3600000) {
			res = t.format("%kh%M'");
		} else if (ms < 60000)
			res = t.format("%S''");
		else
			res = t.format("%M'%S''");

		if (res.charAt(0) == '0') {
			res = res.substring(1);
		}
	}
	return res;
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:22,代碼來源:ArtworkFactory.java

示例11: getDayName

import android.text.format.Time; //導入依賴的package包/類
public String getDayName(long dateInMillis) {
    // If the date is today, return the localized version of "Today" instead of the actual
    // day name.

    Time t = new Time();
    t.setToNow();
    int julianDay = Time.getJulianDay(dateInMillis, t.gmtoff);
    int currentJulianDay = Time.getJulianDay(System.currentTimeMillis(), t.gmtoff);
    if (julianDay == currentJulianDay) {
        return mContext.getString(R.string.today);
    } else if (julianDay == currentJulianDay + 1) {
        return mContext.getString(R.string.tomorrow);
    } else if (julianDay == currentJulianDay - 1) {
        return mContext.getString(R.string.yesterday);
    } else {
        Time time = new Time();
        time.setToNow();
        // Otherwise, the format is just the day of the week (e.g "Wednesday".
        SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE");
        return dayFormat.format(dateInMillis);
    }
}
 
開發者ID:amrendra18,項目名稱:udacity-p3,代碼行數:23,代碼來源:ViewPagerAdapter.java

示例12: onCreate

import android.text.format.Time; //導入依賴的package包/類
@Override
public void onCreate(SurfaceHolder holder){
	super.onCreate(holder);

	setWatchFaceStyle(new WatchFaceStyle.Builder(IOWatchFace.this)
			.setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
			.setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
			.setHotwordIndicatorGravity(Gravity.TOP | Gravity.RIGHT)
			.setShowSystemUiTime(false)
			.setAcceptsTapEvents(true)
			.build());
	Resources resources=IOWatchFace.this.getResources();

	mBackgroundPaint=new Paint();
	//mBackgroundPaint.setColor(0xFFFFFFFF);
	mBackgroundPaint.setColor(0xFF000000);


	paint=new Paint(Paint.ANTI_ALIAS_FLAG);
	paint.setStyle(Paint.Style.STROKE);
	paint.setStrokeWidth(1f*getResources().getDisplayMetrics().density);
	paint.setColor(0xFFFFFFFF);
	//paint.setStrokeCap(Paint.Cap.ROUND);

	time=new Time();
}
 
開發者ID:grishka,項目名稱:io16watchface,代碼行數:27,代碼來源:IOWatchFace.java

示例13: onCreate

import android.text.format.Time; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    Log.d("server",String.valueOf(walk_count));

    gClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    gClient.connect();

    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    registerSensor();
    walk_count = 0;
    today = new Time(Time.getCurrentTimezone());
    today.setToNow();


    Log.d("server","service on");
}
 
開發者ID:longJ91,項目名稱:HoM-Open-API,代碼行數:23,代碼來源:MyService.java

示例14: getRotation

import android.text.format.Time; //導入依賴的package包/類
private HandRotation getRotation(Time time) {
    HandRotation rotation = new HandRotation();

    float minRotationUnit = 360 / 60;
    int min = time.minute;
    float hourH = time.hour < 12 ?
            (float) time.hour + time.minute / 60f :
            (float) (time.hour - 12) + time.minute / 60f;

    rotation.setSecondHand(time.second * minRotationUnit);
    rotation.setMinuteHand(min * minRotationUnit);
    rotation.setHourHand(hourH * 5f * minRotationUnit);

    if (BuildConfig.DEBUG) {
        String tag = this.getClass().getSimpleName();
        Log.d(tag, "時間回転角 = " + String.valueOf(rotation.getHourHand()));
        Log.d(tag, "分回転角 = " + String.valueOf(rotation.getMinuteHand()));
        Log.d(tag, "秒回転角 = " + String.valueOf(rotation.getSecondHand()));
    }

    return rotation;
}
 
開發者ID:f97one,項目名稱:MirageWatch,代碼行數:23,代碼來源:MyWatchFace.java

示例15: timeDay2Day

import android.text.format.Time; //導入依賴的package包/類
public static int timeDay2Day(int day) {
    switch (day) {
        case Time.SUNDAY:
            return SU;
        case Time.MONDAY:
            return MO;
        case Time.TUESDAY:
            return TU;
        case Time.WEDNESDAY:
            return WE;
        case Time.THURSDAY:
            return TH;
        case Time.FRIDAY:
            return FR;
        case Time.SATURDAY:
            return SA;
        default:
            throw new RuntimeException("bad day of week: " + day);
    }
}
 
開發者ID:andela-kogunde,項目名稱:CheckSmarter,代碼行數:21,代碼來源:EventRecurrence.java


注:本文中的android.text.format.Time類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。