Time switchTimezone - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Time switchTimezone method.

This code example shows how to use the following methods:format, set, switchTimezone
package com.ninetwozero.battlelog.util; 
 
import android.text.format.Time; 
 
public class TimeFormatter { 
 
    public static String timeString(int timeValue) {
        Time time = new Time();
        time.switchTimezone("UTC");
        time.set(timeValue * 1000);
        return time.format("%kh%Mm");
    } 
} 

7
CodeRank
This code example shows how to use the following methods:setToNow, switchTimezone
      hand.draw(canvas);
      canvas.restore();
    } 
 
    private void onTimeChanged() { 
        mCalendar.setToNow();
 
        if (mTimeZoneId != null) {
            mCalendar.switchTimezone(mTimeZoneId);
        } 
 
        int hour = mCalendar.hour;
        int minute = mCalendar.minute;
        int second = mCalendar.second;
  //      long millis = System.currentTimeMillis() % 1000; 
 
        mSeconds = second;//(float) ((second * 1000 + millis) / 166.666);
        mMinutes = minute + second / 60.0f;
        mHour = hour + mMinutes / 60.0f;
        mChanged = true;

7
CodeRank
This code example shows how to use the following methods:format, parse3339, switchTimezone
	 * @param dateText the textview which will GET the parsed datestamp set as text 
	 * @param timeText the textview which will GET the parsed timestamp set as text 
	 * @param datetimeStr string in pre-determined format of the datetime to parse 
	 */ 
	public static void setParsedDateTime3999(TextView dateText, TextView timeText, String datetimeStr) {
	    Time readTime = new Time();
	    try { 
			if(readTime.parse3339(datetimeStr)) {  //str was saved out using RFC3339 format, so needs to be read in as such
			    readTime.switchTimezone("Asia/Tokyo");  //parse3339() automatically converts read in times to UTC.  We need to change it back to the default timezone of the handset (JST in this example)
 
			    dateText.setText(readTime.format("%Y-%m-%d"));
			    timeText.setText(readTime.format("%X"));
			} 
		} catch (TimeFormatException e) {
			//in the case of an un-parse-able datetime str, we will just display the str as is instead of trying to prettify it 
			ClLog.e("setParsedDateTime3999():", "created timestamp could not be parsed; skipping"); 
			ClLog.e("setParsedDateTime3999():", e);
			dateText.setText(datetimeStr);
		} 
	} 
7
CodeRank
This code example shows how to use the following methods:setToNow, switchTimezone, toMillis
 
        // NOTE: It's safe to do these after registering the receiver since the receiver always runs 
        // in the main thread, therefore the receiver can't run before this method returns. 
 
        // The time zone may have changed while the receiver wasn't registered, so update the Time 
        mCalendar = new Time();
 
        // Make sure we update to the current time 
        onTimeChanged(); 
 
        // tick the seconds 
        post(mClockTick);
 
    } 
 
    @Override 
    protected void onDetachedFromWindow() { 
        super.onDetachedFromWindow(); 
        if (mAttached) {
            getContext().unregisterReceiver(mIntentReceiver);

6
CodeRank
This code example shows how to use the following methods:format, parse3339, switchTimezone
		} 
		return 0; 
	} 
	 
	public String getLocalTime() {
		Time newTime = new Time("UTC");
		newTime.parse3339(getDate());
		newTime.switchTimezone(localtimezone);
		return  newTime.format("%d-%b-%Y %H:%M:%S");
	} 
	 
	public long getTimeInLong() { 
		Time newTime = new Time("UTC");
		newTime.parse3339(getDate());
		newTime.switchTimezone(localtimezone);
		return newTime.toMillis(false);
	} 
	 
	@Override 
	public String toString() {
6
CodeRank
This code example shows how to use the following methods:format, parse3339, switchTimezone
		return convertedReview;
	} 
	 
	public String getReviewDateInLocalTimezone() {
		if(getReviewDate() != null) { 
			Time newTime = new Time("UTC");
			newTime.switchTimezone(localtimezone);
			newTime.parse3339(getReviewDate());
			return  newTime.format("%d-%b-%Y");
		} 
		 
		return ""; 
	} 
	 
	public String getReviewDate() {
		return reviewDate;
	} 
	 
	public String getLocationName() {
		return this.locationName;
6
CodeRank
This code example shows how to use the following methods:normalize, parse3339, switchTimezone
 
	public static final Time getXmlElementTime(Element parent, String name)
	{ 
		String value = getXmlElementString(parent, name);
		if (value == null || "".equals(value)) return null;
		Time t = new Time();
		t.switchTimezone("UTC");
		try 
		{ 
			t.parse3339(value);
		} 
		catch (TimeFormatException tfe)
		{ 
			Log.e("sync", "Unable to parse DateTime " + value);
			tfe.printStackTrace();
			return null; 
		} 
		t.normalize(false);
		return t;
	} 

6
CodeRank
This code example shows how to use the following methods:format3339, set, switchTimezone
			 
			if (command != null) {
				jsonNote.put("command", command);
			} 
			 
			Time time = new Time();
			time.set(note.getDateUpdate() * 1000);
			time.switchTimezone("GMT");
			 
			jsonNote.put("title", note.getTitle());
			jsonNote.put("note-content", note.getContent());
			jsonNote.put("last-change-date", time.format3339(false));
			jsonNote.put("latest-sync-revision", revision);
			jsonNoteChanges.put(0, jsonNote);
 
			jsonRequest.put("latest-sync-revision", revision);
			jsonRequest.put("note-changes", jsonNoteChanges);
			 
			// TODO: Response should be an object that contains status and response string 
			String response = httpPut(API_URL, jsonRequest.toString(), true);
5
CodeRank
This code example shows how to use the following methods:set, switchTimezone
		{ 
			/* 
			 * Switch to timeZone and reset back to original time zone. That updates date & time to the values in timeZone but keeps the original time zone. 
			 */ 
			String originalTimeZone = time.timezone;
			time.switchTimezone(timeZone);
			time.timezone = originalTimeZone;
			time.set(time.second, time.minute, time.hour, time.monthDay, time.month, time.year);
		} 
	} 
 
 
	@Override 
	public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
	{ 
		mDateTime.year = year;
		mDateTime.month = monthOfYear;
		mDateTime.monthDay = dayOfMonth;
		mDateTime.normalize(true);
		mUpdated = true;
6
CodeRank
This code example shows how to use the following methods:format, parse3339, switchTimezone
		this.askedDate = askedDate;
	}	 
	 
	public String getAskedDateInLocalTimezone() {
		if(getAskedDate() != null) { 
			Time newTime = new Time("UTC");
			newTime.switchTimezone(localtimezone);
			newTime.parse3339(getAskedDate());
			return  newTime.format("%d-%b-%Y");
		} 
		 
		return ""; 
	} 
 
	public String getLatitude() {
		return latitude;
	} 
 
	public void setLatitude(String latitude) {
		this.latitude = latitude;
6
CodeRank
switchTimezone Method Overview
Convert this time object so the time represented remains the same, but is instead located in a different timezone.
See Code Examples for other Android Time Methods: