Example usage for android.text.format Time Time

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

Introduction

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

Prototype

public Time() 

Source Link

Document

Construct a Time object in the default timezone.

Usage

From source file:Main.java

static long getTimestamp() {
    Time time = new Time();
    time.setToNow();
    return time.toMillis(false);
}

From source file:Main.java

public static String GetCurrentFormatTime(String format) {
    Time time = new Time();
    time.setToNow();/*from  w w  w .j  a  v  a  2s . c om*/
    return GetCurrentFormatTime(time.toMillis(false), format);
}

From source file:Main.java

/********** Time **********/

public static long currentTimeInMillis() {
    Time time = new Time();
    time.setToNow();//from w  w  w . jav  a  2s .com
    return time.toMillis(false);
}

From source file:Main.java

public static String getFormattedDate(Context context, long dateInMillis) {
    Time time = new Time();
    time.setToNow();//from  ww w  .j  ava2s .  c  o m
    SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy");
    String dateString = dateFormat.format(dateInMillis);
    return dateString;
}

From source file:Main.java

public static long convertStrTimeToLong(String time_str) {
    /* input time string should have 
     *    - RFC 2445 DATETIM type: "%Y%m%dT%H%M%S"
     *///from   www.  ja  v  a 2 s  .  c o  m
    Time time = new Time();
    time.parse(time_str);
    return time.normalize(false);
}

From source file:Main.java

/**
 * Transform a long representation of a Date into Time 
 * @param dateLong: date in milliseconds from epoch
 * @return time representing the date// w  ww  .j a v  a2  s.  com
 */
public static Time longToTime(long dateLong) {
    Time time = new Time();
    time.set(dateLong);
    return time;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
    Time then = new Time();
    then.set(when);/*from   w w  w.j av a 2  s  .co 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

public static String getTimeAndDate(long j) {
    try {/*from   www  . j  a  v a  2s .  c  om*/
        Calendar instance = Calendar.getInstance();
        TimeZone timeZone = TimeZone.getDefault();
        instance.setTimeInMillis(j);
        instance.add(14, timeZone.getOffset(instance.getTimeInMillis()));
        String format = new SimpleDateFormat(" dd, MMM yyyy").format(instance.getTime());
        Time time = new Time();
        time.set(j);
        return time.format("%H:%M") + format;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

/**
 * Get formatted time./*w  w  w. j  av a2  s . c o m*/
 *
 * @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();
}

From source file:Main.java

/**
 * Parse the given string as a RFC 3339 timestamp, returning the value as
 * milliseconds since the epoch./*ww w  . ja  va  2  s  .  com*/
 */
public static long parseTime(String timestamp) {
    final Time time = new Time();
    time.parse3339(timestamp);
    return time.toMillis(false);
}