当前位置: 首页>>代码示例>>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;未经允许,请勿转载。