热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

android.text.format.Time类的使用及代码示例

本文整理了Java中android.text.format.Time类的一些代码示例,展示了Time类的具体用法。这些代码示例主要来源于

本文整理了Java中android.text.format.Time类的一些代码示例,展示了Time类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Time类的具体详情如下:
包路径:android.text.format.Time
类名称:Time

Time介绍

暂无

代码示例

代码示例来源:origin: wangdan/AisenWeiBo

mYear = params.get(VIEW_PARAMS_YEAR);
final Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
mHasToday = false;
mToday = -1;

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldFormat() throws Exception {
Time t = new Time(Time.TIMEZONE_UTC);
t.set(3600000L);
assertEquals("Hello epoch 01 1970 01", t.format("Hello epoch %d %Y %d"));
assertEquals("Hello epoch 1:00 AM", t.format("Hello epoch %l:%M %p"));
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testSetJulianDay() throws Exception {
Time time = new Time();
time.set(0, 0, 0, 12, 5, 2008);
time.timezOne= "Australia/Sydney";
long millis = time.normalize(true);
int julianDay = Time.getJulianDay(millis, time.gmtoff);
time.setJulianDay(julianDay);
assertTrue(time.hour == 0 || time.hour == 1);
assertEquals(0, time.minute);
assertEquals(0, time.second);
millis = time.toMillis(false);
int day = Time.getJulianDay(millis, time.gmtoff);
assertEquals(day, julianDay);
}
}

代码示例来源:origin: iSoron/uhabits

public synchronized void setJulianDay(int julianDay) {
if (time == null) {
time = new Time();
}
time.setJulianDay(julianDay);
setTime(time.toMillis(false));
}

代码示例来源:origin: robolectric/robolectric

@Test(expected = TimeFormatException.class)
public void shouldThrowTimeFormatException() throws Exception {
Time t = new Time();
t.parse("BLARGH");
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetJulianDay() throws Exception {
Time time = new Time();
time.set(0, 0, 0, 12, 5, 2008);
time.timezOne= "Australia/Sydney";
long millis = time.normalize(true);
// This is the Julian day for 12am for this day of the year
int julianDay = Time.getJulianDay(millis, time.gmtoff);
// Change the time during the day and check that we get the same
// Julian day.
for (int hour = 0; hour <24; hour++) {
for (int minute = 0; minute <60; minute += 15) {
time.set(0, minute, hour, 12, 5, 2008);
millis = time.normalize(true);
int day = Time.getJulianDay(millis, time.gmtoff);
assertEquals(day, julianDay);
}
}
}

代码示例来源:origin: huangfangyi/FanXin

private String getVoiceFileName(String uid) {
Time now = new Time();
now.setToNow();
return uid + now.toString().substring(0, 15) + EXTENSION;
}

代码示例来源:origin: klinker41/android-smsmms

/**
* {@hide}
*/
public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
if (policy.cycleDay == CYCLE_NONE) {
throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
}
final Time now = new Time(policy.cycleTimezone);
now.set(currentTime);
// first, find cycle boundary for current month
final Time cycle = new Time(now);
cycle.hour = cycle.minute = cycle.secOnd= 0;
snapToCycleDay(cycle, policy.cycleDay);
if (Time.compare(cycle, now) <= 0) {
// cycle boundary is before now, use next cycle boundary; start by
// pushing ourselves squarely into next month.
final Time nextMOnth= new Time(now);
nextMonth.hour = nextMonth.minute = nextMonth.secOnd= 0;
nextMonth.mOnthDay= 1;
nextMonth.month += 1;
nextMonth.normalize(true);
cycle.set(nextMonth);
snapToCycleDay(cycle, policy.cycleDay);
}
return cycle.toMillis(true);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldHaveCopyConstructor() throws Exception {
Time t = new Time();
t.setToNow();
Time t2 = new Time(t);
assertEquals(t.timezone, t2.timezone);
assertEquals(t.year, t2.year);
assertEquals(t.month, t2.month);
assertEquals(t.monthDay, t2.monthDay);
assertEquals(t.hour, t2.hour);
assertEquals(t.minute, t2.minute);
assertEquals(t.second, t2.second);
}

代码示例来源:origin: SMSTicket/sms-ticket

final Time now = new Time();
now.setToNow();
now.switchTimezone(Time.getCurrentTimezone());
while (c.moveToNext()) {
final Date validFrom = sdf.parse(c.getString(c.getColumnIndex(Tickets.VALID_FROM)));
final Time vf = new Time();
vf.set(validFrom.getTime());
cv.put(Tickets.VALID_FROM, vf.format3339(false));
final Time vt = new Time();
vt.set(validTo.getTime());
cv.put(Tickets.VALID_TO, vt.format3339(false));
cv.put(Tickets.ORDERED, now.format3339(false));
cv.put(Tickets.STATUS, 7);
cv.put(Tickets.NOTIFICATION_ID, 0);

代码示例来源:origin: iSoron/uhabits

/**
* 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);
}

代码示例来源:origin: SMSTicket/sms-ticket

public static Time timeFrom3339(String s3339) {
final Time time = new Time();
if (TextUtils.isEmpty(s3339)) {
return time;
}
try {
time.parse3339(s3339);
} catch (TimeFormatException e) {
return time;
}
time.switchTimezone(Time.getCurrentTimezone());
return time;
}

代码示例来源:origin: wasdennnoch/AndroidN-ify

+ policy.cycleTimezone);
final Time nowTime = new Time(policy.cycleTimezone);
nowTime.setToNow();
final Time policyTime = new Time(nowTime);
policyTime.set(policy.cycleDay, policyTime.month, policyTime.year);
policyTime.normalize(false);
if (nowTime.after(policyTime)) {
start = policyTime.toMillis(false);
end = addMonth(policyTime, 1).toMillis(false);
} else {
start = addMonth(policyTime, -1).toMillis(false);
end = policyTime.toMillis(false);

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldHaveSet3Args() throws Exception {
Time t = new Time();
t.set(1, 1, 2000);
assertEquals(t.year, 2000);
assertEquals(t.month, 1);
assertEquals(t.monthDay, 1);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldSetToNow() throws Exception {
Time t = new Time();
SystemClock.setCurrentTimeMillis(1000);
t.setToNow();
assertThat(t.toMillis(false)).isEqualTo(1000);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldHaveSetTime() throws Exception {
Time t = new Time();
t.setToNow();
Time t2 = new Time();
t2.set(t);
assertEquals(t.timezone, t2.timezone);
assertEquals(t.year, t2.year);
assertEquals(t.month, t2.month);
assertEquals(t.monthDay, t2.monthDay);
assertEquals(t.hour, t2.hour);
assertEquals(t.minute, t2.minute);
assertEquals(t.second, t2.second);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldHaveToMillis() throws Exception {
Time t = new Time();
t.set(86400 * 1000);
assertEquals(86400 * 1000, t.toMillis(false));
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldSwitchTimeZones() throws Exception {
Time t = new Time("UTC");

t.set(1414213562373L);
assertThat(t.timezone).isEqualTo("UTC");
assertThat(t.gmtoff).isEqualTo(0);
assertThat(t.format3339(false)).isEqualTo("2014-10-25T05:06:02.000Z");

t.switchTimezone("America/New_York");
assertThat(t.format3339(false)).isEqualTo("2014-10-25T01:06:02.000-04:00");
assertThat(t.timezone).isEqualTo("America/New_York");
assertThat(t.gmtoff).isEqualTo(-14400L);
assertThat(t.toMillis(true)).isEqualTo(1414213562000L);
}

代码示例来源:origin: SMSTicket/sms-ticket

/**
* Gets validity of ticket with time {@code t} in minutes.
*/
public static int getValidityMinutes(Time t) {
if (t == null) {
return -1;
}
final Time now = new Time();
now.setToNow();
now.switchTimezone(Time.getCurrentTimezone());
return (int)Math.ceil((t.toMillis(true) - now.toMillis(true)) / 1000d / 60d);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldClear() throws Exception {
Time t = new Time();
t.setToNow();
t.clear("UTC");
assertEquals("UTC", t.timezone);
assertEquals(0, t.year);
assertEquals(0, t.month);
assertEquals(0, t.monthDay);
assertEquals(0, t.hour);
assertEquals(0, t.minute);
assertEquals(0, t.second);
assertEquals(0, t.weekDay);
assertEquals(0, t.yearDay);
assertEquals(0, t.gmtoff);
assertEquals(-1, t.isDst);
}

推荐阅读
author-avatar
张炜26_807
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有