Example usage for android.text.format Time setToNow

List of usage examples for android.text.format Time setToNow

Introduction

In this page you can find the example usage for android.text.format Time setToNow.

Prototype

public void setToNow() 

Source Link

Document

Sets the time of the given Time object to the current time.

Usage

From source file:Main.java

/**
 * @return String//from  w  w w.j  a  v  a  2 s . co m
 * @throws
 * @Title: getTime
 * @Description: TODO
 */
public static String now() {
    Time nowTime = new Time("Asia/chongqing");
    nowTime.setToNow();
    return nowTime.format("%Y%m%d");
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
    Time then = new Time();
    then.set(when);//  w ww .  j  av a 2 s. c o  m

    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        // Otherwise, if the message is from today, show the time.
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    // If the caller has asked for full details, make sure to show the date
    // and time no matter what we've determined above (but still make
    // showing
    // the year only happen if it is a different year from today).
    if (fullFormat) {
        format_flags |= (DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    }

    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:Main.java

private static boolean isTomorrow(long when) {
    Time time = new Time();
    time.set(when);/*  w  ww.ja v  a2 s . c  o  m*/

    int thenYear = time.year;
    int thenMonth = time.month;
    int thenMonthDay = time.monthDay;
    thenMonthDay--;

    time.setToNow();
    return (thenYear == time.year) && (thenMonth == time.month) && (thenMonthDay == time.monthDay);
}

From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java

/**
 * Load the next event in the nextEvent variable.
 *//*from  w w w . java  2  s  . c o m*/
private static void loadNextEvent() {
    Log.d("AlarmService", "nextEvent update");
    long precTime;
    if (nextEvent == null) {
        Time currentDate = new Time();
        currentDate.setToNow();
        Log.d("AlarmService", "currentDate.toMilis= " + currentDate.toMillis(false));
        precTime = currentDate.toMillis(false);
    } else {
        precTime = nextEvent.getBeginTime().toMillis(false);
    }
    Cursor c = LLNCampus.getDatabase()
            .sqlRawQuery("SELECT h.TIME_BEGIN, h.TIME_END, h.COURSE, h.ROOM, c.NAME "
                    + "FROM Horaire as h, Courses as c " + "WHERE h.COURSE = c.CODE AND TIME_BEGIN > "
                    + precTime + " " + "ORDER BY TIME_BEGIN ASC LIMIT 1");
    c.moveToFirst();
    try {
        nextEvent = new Event(c.getLong(0), c.getLong(1));
        nextEvent.addDetail(Event.COURSE, c.getString(2));
        nextEvent.addDetail(Event.ROOM, c.getString(3));
        nextEvent.addDetail(Event.TITLE, c.getString(4));
        c.close();
    } catch (CursorIndexOutOfBoundsException e) // No event yet.
    {
        resetNextEvent();
    }
}

From source file:com.osfans.trime.DictionaryHelper.java

static String getExportName() {
    Time t = new Time();
    t.setToNow();
    return String.format("trime_%s.db", t.format2445());
}

From source file:com.socialdisasters.other.MessageAdapter.java

public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
    Time then = new Time();
    then.set(when);/*from w ww.ja  va  2  s  .c om*/
    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int format_flags = DateUtils.FORMAT_ABBREV_ALL;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        // Otherwise, if the message is from today, show the time.
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    // If the caller has asked for full details, make sure to show the date
    // and time no matter what we've determined above (but still make showing
    // the year only happen if it is a different year from today).
    if (fullFormat) {
        format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    }

    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:com.lottodroid.widgets.wikiarticle.WikiarticleHelper.java

/**
 * Build the page title where it is located today's featured article, like 
 * "Wikipedia:Today's_featured_article/March_21,_2009". It uses the actual date
 * //from   w  ww  .j  a va 2 s.  com
 * @param context The context of the application
 * @return Today's page resource
 */
public static String buildTodayPageTitle(Context context) {
    // Pick out month names from resources
    Resources res = context.getResources();
    String[] monthNames = res.getStringArray(R.array.month_names);

    // Find current month and day
    Time today = new Time();
    today.setToNow();

    // Build today's page title, like "Wikipedia:Today's_featured_article/March_21,_2009"
    String pageName = res.getString(R.string.template_wotd_title, monthNames[today.month], today.monthDay,
            today.year);

    return pageName;
}

From source file:nz.ac.otago.psyanlab.common.util.FileUtils.java

/**
 * Generates a relatively unique path to use as a temporary directory.
 * /*from  w  ww .  j a  v  a  2 s  .c om*/
 * @return
 */
public static String generateTempPath() {
    Time now = new Time();
    now.setToNow();
    return "tmp-" + now.toMillis(false) + "/";
}

From source file:com.example.cal.mysunshine.Utility.java

/**
 * 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.
 *///  w  ww. java2s  .c o m
public static String getFriendlyDayString(Context context, long dateInMillis) {
    // 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 (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);
    }
}

From source file:com.example.mihai.inforoute.app.ForecastFragment.java

public static String getFormattedMonthDay(Context context, long dateInMillis) {
    Time time = new Time();
    time.setToNow();
    SimpleDateFormat dbDateFormat = new SimpleDateFormat(DATE_FORMAT);
    SimpleDateFormat monthDayFormat = new SimpleDateFormat("MMMM dd");
    String monthDayString = monthDayFormat.format(dateInMillis);
    return monthDayString;
}