本文整理匯總了Java中android.text.format.Time.setToNow方法的典型用法代碼示例。如果您正苦於以下問題:Java Time.setToNow方法的具體用法?Java Time.setToNow怎麽用?Java Time.setToNow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.text.format.Time
的用法示例。
在下文中一共展示了Time.setToNow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: 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;
}
示例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);
}
}
示例4: isRightTime
import android.text.format.Time; //導入方法依賴的package包/類
/**
* 獲取當前時間是否大於12:30
*/
public static boolean isRightTime() {
// or Time t=new Time("GMT+8"); 加上Time Zone資料。
Time t = new Time();
t.setToNow(); // 取得係統時間。
int hour = t.hour; // 0-23
int minute = t.minute;
return hour > 12 || (hour == 12 && minute >= 30);
}
示例5: isRightTime
import android.text.format.Time; //導入方法依賴的package包/類
/**
* 獲取當前時間是否大於12:30
*/
public static boolean isRightTime() {
Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone資料。
t.setToNow(); // 取得係統時間。
int hour = t.hour; // 0-23
int minute = t.minute;
return hour > 12 || (hour == 12 && minute >= 30);
}
示例6: getFormattedDate
import android.text.format.Time; //導入方法依賴的package包/類
private static String getFormattedDate() {
Time time = new Time();
time.setToNow();
DateFormat.getDateInstance();
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
return formattedDate;
}
示例7: generateTimeStampPhotoFileUri
import android.text.format.Time; //導入方法依賴的package包/類
private Uri generateTimeStampPhotoFileUri() {
Uri photoFileUri = null;
File outputDir = getPhotoDirectory();
if (outputDir != null) {
Time t = new Time();
t.setToNow();
File photoFile = new File(outputDir, System.currentTimeMillis()
+ ".jpg");
//photoFileUri = Uri.fromFile(photoFile);
photoFileUri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", photoFile);
}
return photoFileUri;
}
示例8: getUserZoneMillis
import android.text.format.Time; //導入方法依賴的package包/類
/**
* 將UTC-0時區時間字符串轉換成用戶時區時間距離1970-01-01的毫秒數.
*
* @param strUtcTime UTC-0時區的時間字符串
* @param strInFmt 時間格式
* @return 用戶時區時間距離1970-01-01的毫秒數.
* @throws ParseException 時間轉換異常
*/
public static long getUserZoneMillis(final String strUtcTime,
final String strInFmt) throws ParseException {
if (StringUtils.isNull(strUtcTime)) {
throw new NullPointerException("參數strUtcTime不能為空");
} else if (StringUtils.isNull(strInFmt)) {
throw new NullPointerException("參數strInFmt不能為空");
}
long lUtcMillis = parseMillis(strUtcTime, strInFmt);
Time time = new Time();
time.setToNow();
long lOffset = time.gmtoff * DateUtils.SECOND_IN_MILLIS;
long lUserZoneMillis = lUtcMillis + lOffset;
return lUserZoneMillis;
}
示例9: getFriendlyDayString
import android.text.format.Time; //導入方法依賴的package包/類
/**
* Helper method to convert the database representation of the date into something to display
* to users. As classy and polished a user experience as "20140102" is, we can do better.
*
* @param context Context to use for resource localization
* @param dateInMillis The date in milliseconds
* @return a user-friendly representation of the date.
*/
public static String getFriendlyDayString(Context context, long dateInMillis, boolean displayLongToday) {
// The day string for forecast uses the following logic:
// For today: "Today, June 8"
// For tomorrow: "Tomorrow"
// For the next 5 days: "Wednesday" (just the day name)
// For all days after that: "Mon Jun 8"
Time time = new Time();
time.setToNow();
long currentTime = System.currentTimeMillis();
int julianDay = Time.getJulianDay(dateInMillis, time.gmtoff);
int currentJulianDay = Time.getJulianDay(currentTime, time.gmtoff);
// If the date we're building the String for is today's date, the format
// is "Today, June 24"
if (displayLongToday && julianDay == currentJulianDay) {
String today = context.getString(R.string.today);
int formatId = R.string.format_full_friendly_date;
return String.format(context.getString(
formatId,
today,
getFormattedMonthDay(context, dateInMillis)));
} else if ( julianDay < currentJulianDay + 7 ) {
// If the input date is less than a week in the future, just return the day name.
return getDayName(context, dateInMillis);
} else {
// Otherwise, use the form "Mon Jun 3"
SimpleDateFormat shortenedDateFormat = new SimpleDateFormat("EEE MMM dd");
return shortenedDateFormat.format(dateInMillis);
}
}
示例10: pictureName
import android.text.format.Time; //導入方法依賴的package包/類
public String pictureName() {
String str = "";
Time t = new Time();
t.setToNow(); // 取得係統時間。
int year = t.year;
int month = t.month + 1;
int date = t.monthDay;
int hour = t.hour; // 0-23
int minute = t.minute;
int second = t.second;
if (month < 10)
str = String.valueOf(year) + "0" + String.valueOf(month);
else {
str = String.valueOf(year) + String.valueOf(month);
}
if (date < 10)
str = str + "0" + String.valueOf(date + "_");
else {
str = str + String.valueOf(date + "_");
}
if (hour < 10)
str = str + "0" + String.valueOf(hour);
else {
str = str + String.valueOf(hour);
}
if (minute < 10)
str = str + "0" + String.valueOf(minute);
else {
str = str + String.valueOf(minute);
}
if (second < 10)
str = str + "0" + String.valueOf(second);
else {
str = str + String.valueOf(second);
}
return str;
}
示例11: pictureName
import android.text.format.Time; //導入方法依賴的package包/類
public String pictureName() {
String str = "";
Time t = new Time();
t.setToNow();
int year = t.year;
int month = t.month + 1;
int date = t.monthDay;
int hour = t.hour; // 0-23
int minute = t.minute;
int second = t.second;
if (month < 10)
str = String.valueOf(year) + "0" + String.valueOf(month);
else {
str = String.valueOf(year) + String.valueOf(month);
}
if (date < 10)
str = str + "0" + String.valueOf(date + "_");
else {
str = str + String.valueOf(date + "_");
}
if (hour < 10)
str = str + "0" + String.valueOf(hour);
else {
str = str + String.valueOf(hour);
}
if (minute < 10)
str = str + "0" + String.valueOf(minute);
else {
str = str + String.valueOf(minute);
}
if (second < 10)
str = str + "0" + String.valueOf(second);
else {
str = str + String.valueOf(second);
}
return str;
}
示例12: getFormattedMonthDay
import android.text.format.Time; //導入方法依賴的package包/類
/**
* Converts db date format to the format "Month day", e.g "June 24".
* @param context Context to use for resource localization
* @param dateInMillis The db formatted date string, expected to be of the form specified
* in Utility.DATE_FORMAT
* @return The day in the form of a string formatted "December 6"
*/
public static String getFormattedMonthDay(Context context, long dateInMillis ) {
Time time = new Time();
time.setToNow();
SimpleDateFormat dbDateFormat = new SimpleDateFormat(Utility.DATE_FORMAT);
SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd");
String monthDayString = monthDayFormat.format(dateInMillis);
return monthDayString;
}
示例13: getCurrentTime
import android.text.format.Time; //導入方法依賴的package包/類
/**
* Returns the current time in the time zone that is currently set for the device.
*
* @return An instance of the Time class representing the current moment, specified with second precision
*/
public static Time getCurrentTime() {
Time now = new Time(Time.getCurrentTimezone());
now.setToNow();
return now;
}
示例14: stopRefresh
import android.text.format.Time; //導入方法依賴的package包/類
/**
* stop refresh, reset header view.
*/
public void stopRefresh() {
Time time = new Time();
time.setToNow();
mHeaderView.setRefreshTime(time.format("%Y-%m-%d %T"));
if (mPullRefreshing == true) {
mPullRefreshing = false;
resetHeaderHeight();
}
}
示例15: getFormattedMonthDay
import android.text.format.Time; //導入方法依賴的package包/類
/**
* Converts db date format to the format "Month day", e.g "June 24".
* @param context Context to use for resource localization
* @param dateInMillis The db formatted date string, expected to be of the form specified
* in Utility.DATE_FORMAT
* @return The day in the form of a string formatted "December 6"
*/
public static String getFormattedMonthDay(Context context, long dateInMillis ) {
Time time = new Time();
time.setToNow();
SimpleDateFormat dbDateFormat = new SimpleDateFormat(WeatherUtil.DATE_FORMAT);
SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd");
String monthDayString = monthDayFormat.format(dateInMillis);
return monthDayString;
}