当前位置: 首页>>代码示例>>Java>>正文


Java Time.setToNow方法代码示例

本文整理汇总了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);
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:20,代码来源:Utils.java

示例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;
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:24,代码来源:Beam.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:sahilandroid19,项目名称:WearApp,代码行数:29,代码来源:Utility.java

示例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);
}
 
开发者ID:joelan,项目名称:ClouldReader,代码行数:12,代码来源:TimeUtil.java

示例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);
}
 
开发者ID:lai233333,项目名称:MyDemo,代码行数:11,代码来源:TimeUtil.java

示例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;
	}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:11,代码来源:TitleViewUtil.java

示例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;
    }
 
开发者ID:xeliot,项目名称:ChewSnap,代码行数:15,代码来源:PopDish.java

示例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;
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:23,代码来源:DateTimeUtils.java

示例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);
    }
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:40,代码来源:Utility.java

示例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;
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:38,代码来源:OrcPlatsActivity.java

示例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;
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:38,代码来源:OrcVinActivity.java

示例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;
}
 
开发者ID:ravi923615,项目名称:Sunshine,代码行数:16,代码来源:Utility.java

示例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;
}
 
开发者ID:manishpatelgt,项目名称:MyTwitterRepo,代码行数:12,代码来源:TimeHelper.java

示例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();
	}
}
 
开发者ID:JasonGaoH,项目名称:enjoychat,代码行数:13,代码来源:XListView.java

示例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;
}
 
开发者ID:katamaditya,项目名称:Weather4U,代码行数:16,代码来源:WeatherUtil.java


注:本文中的android.text.format.Time.setToNow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。