Search in sources :

Example 26 with GregorianCalendar

use of java.util.GregorianCalendar in project android-app by eoecn.

the class DateUtil method getDateByAddFltHour.

/**
	 * 返回当前时间加实数小时后的日期时间。
	 * <p>
	 * 格式:yyyy-MM-dd HH:mm:ss
	 * 
	 * @return Float 加几实数小时.
	 */
public static String getDateByAddFltHour(float flt) {
    int addMinute = (int) (flt * 60);
    Calendar cal = new GregorianCalendar();
    cal.setTime(new Date());
    cal.add(GregorianCalendar.MINUTE, addMinute);
    return getFormatDateTime(cal.getTime(), "yyyy-MM-dd HH:mm:ss");
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 27 with GregorianCalendar

use of java.util.GregorianCalendar in project android-app by eoecn.

the class DateUtil method getDateByAddHour.

/**
	 * 返回指定时间加指定小时数后的日期时间。
	 * <p>
	 * 格式:yyyy-MM-dd HH:mm:ss
	 * 
	 * @return 时间.
	 */
public static String getDateByAddHour(String datetime, int minute) {
    String returnTime = null;
    Calendar cal = new GregorianCalendar();
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date;
    try {
        date = ft.parse(datetime);
        cal.setTime(date);
        cal.add(GregorianCalendar.MINUTE, minute);
        returnTime = getFormatDateTime(cal.getTime(), "yyyy-MM-dd HH:mm:ss");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return returnTime;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 28 with GregorianCalendar

use of java.util.GregorianCalendar in project MyDiary by erttyy8821.

the class EntriesAdapter method showHeader.

private boolean showHeader(final int position) {
    if (position == 0) {
        return true;
    } else {
        Calendar previousCalendar = new GregorianCalendar();
        previousCalendar.setTime(entriesList.get(position - 1).getCreateDate());
        Calendar currentCalendar = new GregorianCalendar();
        currentCalendar.setTime(entriesList.get(position).getCreateDate());
        if (previousCalendar.get(Calendar.YEAR) != currentCalendar.get(Calendar.YEAR)) {
            return true;
        } else {
            if (previousCalendar.get(Calendar.MONTH) != currentCalendar.get(Calendar.MONTH)) {
                return true;
            } else {
                return false;
            }
        }
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 29 with GregorianCalendar

use of java.util.GregorianCalendar in project nikeplus-fuelband-se-reversed by evilsocket.

the class Utils method processGetSettingsResponse.

public static void processGetSettingsResponse(byte[] raw) throws Exception {
    ByteBuffer byteBuffer = ByteBuffer.wrap(raw);
    // skip protocol first four bytes
    byte dummy1 = byteBuffer.get();
    byte dummy2 = byteBuffer.get();
    byte dummy3 = byteBuffer.get();
    byte dummy4 = byteBuffer.get();
    byte elements = byteBuffer.get();
    if (elements <= 0) {
        return;
    }
    for (byte b = 0; b < elements; ++b) {
        if (byteBuffer.remaining() < 2) {
            throw new Exception("Decoding error, not enough remaining bytes");
        }
        byte configKey = byteBuffer.get();
        byte valueSize = byteBuffer.get();
        valueSize = (byte) (Math.min((int) valueSize, byteBuffer.remaining()) & 0xFF);
        final String settingKey = getSettingKey(configKey);
        if (settingKey == null) {
            Logger.e("Unknown config key " + configKey);
            byteBuffer.position(valueSize + byteBuffer.position());
        } else {
            switch(getSettingType(configKey)) {
                case BYTE:
                    {
                        Logger.i("Got setting: " + settingKey + " = " + (byteBuffer.get() & 0xFF));
                        break;
                    }
                case BYTE_ARRAY:
                    {
                        final byte[] array = new byte[valueSize];
                        byteBuffer.get(array);
                        Logger.i("Got setting: " + settingKey + " = " + Utils.bytesToHex(array));
                        break;
                    }
                case STRING:
                    {
                        final byte[] array2 = new byte[valueSize];
                        byteBuffer.get(array2);
                        byte b2;
                        for (b2 = 0; b2 < valueSize && array2[b2] != 0; ++b2) {
                        }
                        Logger.i("Got setting: " + settingKey + " = " + new String(array2, 0, b2, Charset.forName("US-ASCII")));
                        break;
                    }
                case UINT32:
                    {
                        Logger.i("Got setting: " + settingKey + " = " + byteBuffer.getInt());
                        break;
                    }
                case UINT16:
                    {
                        Logger.i("Got setting: " + settingKey + " = " + byteBuffer.getShort());
                        break;
                    }
                case BOOLEAN:
                    {
                        Logger.i("Got setting: " + settingKey + " = " + (byteBuffer.get() == 0 ? "false" : "true"));
                        break;
                    }
                case DOB_CALENDAR:
                    {
                        final int int1 = byteBuffer.getInt();
                        Logger.i("Got setting: " + settingKey + " = " + (new GregorianCalendar(int1 & 0xFFFF, -1 + (0xFF & int1 >>> 16), int1 >>> 24)));
                        break;
                    }
                case GENDER:
                    {
                        String gender = "UNKNOWN";
                        switch(byteBuffer.get()) {
                            case 77:
                                {
                                    gender = "MALE";
                                    break;
                                }
                            case 70:
                                {
                                    gender = "FEMALE";
                                    break;
                                }
                        }
                        Logger.i("Got setting: " + settingKey + " = " + gender);
                        break;
                    }
                default:
                    throw new Exception("Unknown config type");
            }
        }
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) ByteBuffer(java.nio.ByteBuffer)

Example 30 with GregorianCalendar

use of java.util.GregorianCalendar in project android_frameworks_base by ParanoidAndroid.

the class DateUtils method formatSameDayTime.

/**
     * Format a date / time such that if the then is on the same day as now, it shows
     * just the time and if it's a different day, it shows just the date.
     *
     * <p>The parameters dateFormat and timeFormat should each be one of
     * {@link java.text.DateFormat#DEFAULT},
     * {@link java.text.DateFormat#FULL},
     * {@link java.text.DateFormat#LONG},
     * {@link java.text.DateFormat#MEDIUM}
     * or
     * {@link java.text.DateFormat#SHORT}
     *
     * @param then the date to format
     * @param now the base time
     * @param dateStyle how to format the date portion.
     * @param timeStyle how to format the time portion.
     */
public static final CharSequence formatSameDayTime(long then, long now, int dateStyle, int timeStyle) {
    Calendar thenCal = new GregorianCalendar();
    thenCal.setTimeInMillis(then);
    Date thenDate = thenCal.getTime();
    Calendar nowCal = new GregorianCalendar();
    nowCal.setTimeInMillis(now);
    java.text.DateFormat f;
    if (thenCal.get(Calendar.YEAR) == nowCal.get(Calendar.YEAR) && thenCal.get(Calendar.MONTH) == nowCal.get(Calendar.MONTH) && thenCal.get(Calendar.DAY_OF_MONTH) == nowCal.get(Calendar.DAY_OF_MONTH)) {
        f = java.text.DateFormat.getTimeInstance(timeStyle);
    } else {
        f = java.text.DateFormat.getDateInstance(dateStyle);
    }
    return f.format(thenDate);
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Context(android.content.Context) Date(java.util.Date)

Aggregations

GregorianCalendar (java.util.GregorianCalendar)1212 Calendar (java.util.Calendar)574 Date (java.util.Date)358 Test (org.junit.Test)233 SimpleDateFormat (java.text.SimpleDateFormat)100 Timestamp (java.sql.Timestamp)54 ScheduleExpression (javax.ejb.ScheduleExpression)51 ArrayList (java.util.ArrayList)47 EJBCronTrigger (org.apache.openejb.core.timer.EJBCronTrigger)42 HashMap (java.util.HashMap)41 ParseException (java.text.ParseException)38 TimeZone (java.util.TimeZone)38 SimpleTimeZone (java.util.SimpleTimeZone)35 BigDecimal (java.math.BigDecimal)32 Date (java.sql.Date)30 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)21 DateFormat (java.text.DateFormat)18 SQLException (java.sql.SQLException)17 Map (java.util.Map)16 Meeting (net.johnpwood.android.standuptimer.model.Meeting)16