本文整理汇总了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;
}