Java Code Examples for android.text.format.Time#setToNow()
The following examples show how to use
android.text.format.Time#setToNow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: pubFun.java From accountBook with Apache License 2.0 | 6 votes |
/** * 获取当前年月日 * 输出的值为System.out: 月:8 ##年:2018 ##日:20 ##时:11(其中输出的月份的值是实际月份-1) * @param strFlag * @return */ public static Integer getTime(String strFlag){ Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料 t.setToNow(); // 取得系统时间 int reValue = 0; if(strFlag == "Y"){ reValue = t.year; }else if(strFlag == "M"){ reValue = t.month; }else if(strFlag == "D"){ reValue = t.monthDay; }else if(strFlag == "H"){ reValue = t.hour; } return reValue; }
Example 2
Source File: PrefUtils.java From styT with Apache License 2.0 | 6 votes |
public static String getSystemTime() { Time t = new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。 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; String tag = "AM"; if (hour >= 12) { tag = "PM"; } return date + "/" + month + "/" + year + " " + hour + ":" + minute + " " + tag; }
Example 3
Source File: Utility.java From Krishi-Seva with MIT License | 6 votes |
/** * 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); } }
Example 4
Source File: Utility.java From Advanced_Android_Development with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 5
Source File: GosScheduleEditDateAcitivty.java From Gizwits-SmartBuld_Android with MIT License | 5 votes |
/** * Description:根据时间在云端创建规则和更新数据库 */ private void setRuleOnSiteAndUpdateDateBase() { final String utcDate; final String utcTime; Time nowTime = new Time(); nowTime.setToNow(); int now = nowTime.hour * 60 + nowTime.minute; int pick = npHour.getValue() * 60 + npMin.getValue(); if (selectDate.getUserPickRepeat().equals("none")) { // 没有重复天数 if (now < pick) { // 当前时间早于选择时间,设置为今天 selectDate.setDateTimeToToday( String.format("%02d", npHour.getValue()) + ":" + String.format("%02d", npMin.getValue())); } else { // 当前时间晚于选择时间,设置为明天 selectDate.setDateTimeToTomorrow( String.format("%02d", npHour.getValue()) + ":" + String.format("%02d", npMin.getValue())); } } else { // 有重复天数 utcDate = ""; utcTime = GetUTCTimeUtil.getUTCTimeFromLocal( String.format("%02d", npHour.getValue()) + ":" + String.format("%02d", npMin.getValue())); setRepeatDateAccordingPickTime(pick); selectDate.setDate(utcDate); selectDate.setTime(utcTime); } progressDialog.show(); selectDate.setOnSite(handler); }
Example 6
Source File: Utility.java From Advanced_Android_Development with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 7
Source File: Utils.java From android-discourse with Apache License 2.0 | 5 votes |
public static boolean isInOneMonth(long when) { Time time = new Time(); time.set(when + DAY_30); Time now = new Time(); now.setToNow(); if (time.before(now)) { return false; } return true; }
Example 8
Source File: GosScheduleData.java From Gizwits-SmartBuld_Android with MIT License | 5 votes |
/** * Description:返回当前时间,比如201608061120,中间没有任何符号 */ private String getLocalTimeString() { Time nowTime = new Time(); nowTime.setToNow(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(nowTime.year); stringBuilder.append(String.format("%02d", nowTime.month + 1)); stringBuilder.append(String.format("%02d", nowTime.monthDay)); stringBuilder.append(String.format("%02d", nowTime.hour)); stringBuilder.append(String.format("%02d", nowTime.minute)); return stringBuilder.toString(); }
Example 9
Source File: SimpleMonthView.java From CalendarListview with MIT License | 5 votes |
public SimpleMonthView(Context context, TypedArray typedArray) { super(context); Resources resources = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); today = new Time(Time.getCurrentTimezone()); today.setToNow(); mDayOfWeekTypeface = resources.getString(R.string.sans_serif); mMonthTitleTypeface = resources.getString(R.string.sans_serif); mCurrentDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorCurrentDay, resources.getColor(R.color.normal_day)); mMonthTextColor = typedArray.getColor(R.styleable.DayPickerView_colorMonthName, resources.getColor(R.color.normal_day)); mDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorDayName, resources.getColor(R.color.normal_day)); mDayNumColor = typedArray.getColor(R.styleable.DayPickerView_colorNormalDay, resources.getColor(R.color.normal_day)); mPreviousDayColor = typedArray.getColor(R.styleable.DayPickerView_colorPreviousDay, resources.getColor(R.color.normal_day)); mSelectedDaysColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayBackground, resources.getColor(R.color.selected_day_background)); mMonthTitleBGColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayText, resources.getColor(R.color.selected_day_text)); mDrawRect = typedArray.getBoolean(R.styleable.DayPickerView_drawRoundRect, false); mStringBuilder = new StringBuilder(50); MINI_DAY_NUMBER_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDay, resources.getDimensionPixelSize(R.dimen.text_size_day)); MONTH_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeMonth, resources.getDimensionPixelSize(R.dimen.text_size_month)); MONTH_DAY_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDayName, resources.getDimensionPixelSize(R.dimen.text_size_day_name)); MONTH_HEADER_SIZE = typedArray.getDimensionPixelOffset(R.styleable.DayPickerView_headerMonthHeight, resources.getDimensionPixelOffset(R.dimen.header_month_height)); DAY_SELECTED_CIRCLE_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_selectedDayRadius, resources.getDimensionPixelOffset(R.dimen.selected_day_radius)); mRowHeight = ((typedArray.getDimensionPixelSize(R.styleable.DayPickerView_calendarHeight, resources.getDimensionPixelOffset(R.dimen.calendar_height)) - MONTH_HEADER_SIZE) / 6); isPrevDayEnabled = typedArray.getBoolean(R.styleable.DayPickerView_enablePreviousDay, true); initView(); }
Example 10
Source File: TimeUtil.java From CloudReader with Apache License 2.0 | 5 votes |
/** * 获取当前时间是否大于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); }
Example 11
Source File: TabooProxy.java From MaterialCalendar with Apache License 2.0 | 5 votes |
public static Taboo getTodayTaboo() { Time time = new Time(); time.setToNow(); int month = time.month + 1; String todayDate = String.valueOf(time.year) + String.valueOf(month < 10 ? "0" + month : month) + String.valueOf(time.monthDay); return getTabooByDate(todayDate); }
Example 12
Source File: TitleViewUtil.java From android-tv-launcher with MIT License | 5 votes |
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; }
Example 13
Source File: Utility.java From Krishi-Seva with MIT License | 5 votes |
/** * 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) { // 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); } }
Example 14
Source File: SimpleMonthView.java From UltimateAndroid with Apache License 2.0 | 5 votes |
public SimpleMonthView(Context context, TypedArray typedArray) { super(context); Resources resources = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); today = new Time(Time.getCurrentTimezone()); today.setToNow(); mDayOfWeekTypeface = "sans_serif"; mMonthTitleTypeface = "sans_serif"; mCurrentDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorCurrentDay, resources.getColor(R.color.normal_day)); mMonthTextColor = typedArray.getColor(R.styleable.DayPickerView_colorMonthName, resources.getColor(R.color.normal_day)); mDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorDayName, resources.getColor(R.color.normal_day)); mDayNumColor = typedArray.getColor(R.styleable.DayPickerView_colorNormalDay, resources.getColor(R.color.normal_day)); mPreviousDayColor = typedArray.getColor(R.styleable.DayPickerView_colorPreviousDay, resources.getColor(R.color.normal_day)); mSelectedDaysColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayBackground, resources.getColor(R.color.selected_day_background)); mMonthTitleBGColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayText, resources.getColor(R.color.selected_day_text)); mDrawRect = typedArray.getBoolean(R.styleable.DayPickerView_drawRoundRect, false); mStringBuilder = new StringBuilder(50); MINI_DAY_NUMBER_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDay, resources.getDimensionPixelSize(R.dimen.text_size_day)); MONTH_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeMonth, resources.getDimensionPixelSize(R.dimen.text_size_month)); MONTH_DAY_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDayName, resources.getDimensionPixelSize(R.dimen.text_size_day_name)); MONTH_HEADER_SIZE = typedArray.getDimensionPixelOffset(R.styleable.DayPickerView_headerMonthHeight, resources.getDimensionPixelOffset(R.dimen.header_month_height)); DAY_SELECTED_CIRCLE_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_selectedDayRadius, resources.getDimensionPixelOffset(R.dimen.selected_day_radius)); mRowHeight = ((typedArray.getDimensionPixelSize(R.styleable.DayPickerView_calendarHeight, resources.getDimensionPixelOffset(R.dimen.calendar_height)) - MONTH_HEADER_SIZE) / 6); isPrevDayEnabled = typedArray.getBoolean(R.styleable.DayPickerView_enablePreviousDay, true); initView(); }
Example 15
Source File: EaseVoiceRecorder.java From Study_Android_Demo with Apache License 2.0 | 4 votes |
private String getVoiceFileName(String uid) { Time now = new Time(); now.setToNow(); return uid + now.toString().substring(0, 15) + EXTENSION; }
Example 16
Source File: BaseTaskViewDescriptor.java From opentasks with Apache License 2.0 | 4 votes |
protected void setDueDate(TextView view, ImageView dueIcon, Time dueDate, boolean isClosed) { if (view != null && dueDate != null) { Time now = mNow; if (now == null) { now = mNow = new Time(); } if (!now.timezone.equals(TimeZone.getDefault().getID())) { now.clear(TimeZone.getDefault().getID()); } if (Math.abs(now.toMillis(false) - System.currentTimeMillis()) > 5000) { now.setToNow(); now.normalize(true); } dueDate.normalize(true); view.setText(new DateFormatter(view.getContext()).format(dueDate, now, DateFormatContext.LIST_VIEW)); if (dueIcon != null) { dueIcon.setVisibility(View.VISIBLE); } // highlight overdue dates & times, handle allDay tasks separately if ((!dueDate.allDay && dueDate.before(now) || dueDate.allDay && (dueDate.year < now.year || dueDate.yearDay <= now.yearDay && dueDate.year == now.year)) && !isClosed) { view.setTextAppearance(view.getContext(), R.style.task_list_overdue_text); } else { view.setTextAppearance(view.getContext(), R.style.task_list_due_text); } } else if (view != null) { view.setText(""); if (dueIcon != null) { dueIcon.setVisibility(View.GONE); } } }
Example 17
Source File: MonthView.java From cathode with Apache License 2.0 | 4 votes |
/** * Sets all the parameters for displaying this week. The only required * parameter is the week number. Other parameters have a default value and * will only update if a new value is included, except for focus month, * which will always default to no focus month if no value is passed in. See * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters. * * @param params A map of the new parameters, see * {@link #VIEW_PARAMS_HEIGHT} */ public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify month and year for this view"); } setTag(params); // We keep the current value for any params not present if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) { mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY); } // Allocate space for caching the day numbers and focus values mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = Utils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mTouchHelper.invalidateRoot(); }
Example 18
Source File: MonthView.java From StyleableDateTimePicker with MIT License | 4 votes |
/** * Sets all the parameters for displaying this week. The only required * parameter is the week number. Other parameters have a default value and * will only update if a new value is included, except for focus month, * which will always default to no focus month if no value is passed in. See * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters. * * @param params A map of the new parameters, see * {@link #VIEW_PARAMS_HEIGHT} */ public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify month and year for this view"); } setTag(params); // We keep the current value for any params not present if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) { mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY); } // Allocate space for caching the day numbers and focus values mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = Utils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mTouchHelper.invalidateRoot(); }
Example 19
Source File: MonthView.java From BottomSheetPickers with Apache License 2.0 | 4 votes |
/** * Sets all the parameters for displaying this week. The only required * parameter is the week number. Other parameters have a default value and * will only update if a new value is included, except for focus month, * which will always default to no focus month if no value is passed in. See * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters. * * @param params A map of the new parameters, see * {@link #VIEW_PARAMS_HEIGHT} */ public void setMonthParams(HashMap<String, Integer> params) { if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { throw new InvalidParameterException("You must specify month and year for this view"); } setTag(params); // We keep the current value for any params not present if (params.containsKey(VIEW_PARAMS_HEIGHT)) { mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) { mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY); } // Allocate space for caching the day numbers and focus values mMonth = params.get(VIEW_PARAMS_MONTH); mYear = params.get(VIEW_PARAMS_YEAR); // Figure out what day today is final Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); mHasToday = false; mToday = -1; mCalendar.set(Calendar.MONTH, mMonth); mCalendar.set(Calendar.YEAR, mYear); mCalendar.set(Calendar.DAY_OF_MONTH, 1); mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); if (params.containsKey(VIEW_PARAMS_WEEK_START)) { mWeekStart = params.get(VIEW_PARAMS_WEEK_START); } else { mWeekStart = mCalendar.getFirstDayOfWeek(); } mNumCells = Utils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; if (sameDay(day, today)) { mHasToday = true; mToday = day; } } mNumRows = calculateNumRows(); // Invalidate cached accessibility information. mTouchHelper.invalidateRoot(); }
Example 20
Source File: LocationHandler.java From FancyPlaces with GNU General Public License v3.0 | 3 votes |
protected Boolean isValidLocation(Location location) { if (location == null) return false; Time now = new Time(); now.setToNow(); return (now.toMillis(true) - location.getTime()) <= TWO_MINUTES; }