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


Java Time.getJulianDay方法代码示例

本文整理汇总了Java中android.text.format.Time.getJulianDay方法的典型用法代码示例。如果您正苦于以下问题:Java Time.getJulianDay方法的具体用法?Java Time.getJulianDay怎么用?Java Time.getJulianDay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.format.Time的用法示例。


在下文中一共展示了Time.getJulianDay方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: Day

import android.text.format.Time; //导入方法依赖的package包/类
public Day(Context context,int day, int year, int month){
	this.day = day;
	this.year = year;
	this.month = month;
	this.context = context;
	Calendar cal = Calendar.getInstance();
	cal.set(year, month-1, day);
	int end = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	cal.set(year, month, end);
	TimeZone tz = TimeZone.getDefault();
	monthEndDay = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));
}
 
开发者ID:ur13l,项目名称:Guanajoven,代码行数:13,代码来源:Day.java

示例4: normalizeDate

import android.text.format.Time; //导入方法依赖的package包/类
public static long normalizeDate(long startDate) {
    // normalize the start date to the beginning of the (UTC) day
    Time time = new Time();
    time.set(startDate);
    int julianDay = Time.getJulianDay(startDate, time.gmtoff);
    return time.setJulianDay(julianDay);
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:8,代码来源:WeatherContract.java

示例5: 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

示例6: getFormattedTime

import android.text.format.Time; //导入方法依赖的package包/类
/**
 * Get formatted time.
 *
 * @param publishedTime The published time in millis.
 *
 * @return The formatted time.
 */
static public String getFormattedTime(long publishedTime) {
    // This is copied from RecentCallsListActivity.java

    long now = System.currentTimeMillis();

    // Set the date/time field by mixing relative and absolute times.
    int flags = DateUtils.FORMAT_ABBREV_ALL;

    if (!DateUtils.isToday(publishedTime)) {
        // DateUtils.getRelativeTimeSpanString doesn't consider the nature
        // days comparing with DateUtils.getRelativeDayString. Override the
        // real date to implement the requirement.

        Time time = new Time();
        time.set(now);
        long gmtOff = time.gmtoff;
        int days = Time.getJulianDay(publishedTime, gmtOff) - Time.getJulianDay(now, gmtOff);

        // Set the delta from now to get the correct display
        publishedTime = now + days * DateUtils.DAY_IN_MILLIS;
    } else if (publishedTime > now && (publishedTime - now) < DateUtils.HOUR_IN_MILLIS) {
        // Avoid e.g. "1 minute left" when publish time is "07:00" and
        // current time is "06:58"
        publishedTime += DateUtils.MINUTE_IN_MILLIS;
    }

    return (DateUtils.getRelativeTimeSpanString(publishedTime, now, DateUtils.MINUTE_IN_MILLIS,
            flags)).toString();
}
 
开发者ID:fbarriga,项目名称:sony-smartband-logger,代码行数:37,代码来源:ExtensionUtils.java


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