當前位置: 首頁>>代碼示例>>Java>>正文


Java MutableDateTime類代碼示例

本文整理匯總了Java中org.joda.time.MutableDateTime的典型用法代碼示例。如果您正苦於以下問題:Java MutableDateTime類的具體用法?Java MutableDateTime怎麽用?Java MutableDateTime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MutableDateTime類屬於org.joda.time包,在下文中一共展示了MutableDateTime類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processAlertNotification

import org.joda.time.MutableDateTime; //導入依賴的package包/類
private void processAlertNotification(Bundle data) {

        String pubUsername = data.getString(PUBLISHER_USERNAME);
        String type = data.getString(ALERT_TYPE).toLowerCase();

        long timestamp = Long.parseLong(data.getString(ALERT_TIMESTAMP));
        MutableDateTime date = new MutableDateTime(timestamp);
        DateTimeFormatter dtf = DateTimeFormat.forPattern("kk:mm dd/MM/yyyy");

        int notificationId = 2;

        String msg =  "Alert from " + pubUsername + "\nType: " + type + "\nDate: " + date.toString(dtf);

        Notification.Builder notificationBuilder = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("MAGPIE Notification")
                .setContentText("Alert from " + pubUsername)
                .setStyle(new Notification.BigTextStyle().bigText(msg));

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationId, notificationBuilder.build());

    }
 
開發者ID:kflauri2312lffds,項目名稱:Android_watch_magpie,代碼行數:24,代碼來源:GcmMessageHandler.java

示例2: testRoundingWithTimeZone

import org.joda.time.MutableDateTime; //導入依賴的package包/類
public void testRoundingWithTimeZone() {
    MutableDateTime time = new MutableDateTime(DateTimeZone.UTC);
    time.setZone(DateTimeZone.forOffsetHours(-2));
    time.setRounding(time.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC);
    utcTime.setRounding(utcTime.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    time.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));

    assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-03T00:00:00.000Z"));
    // the time is on the 2nd, and utcTime is on the 3rd, but, because time already encapsulates
    // time zone, the millis diff is not 24, but 22 hours
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));

    time.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    assertThat(time.toString(), equalTo("2009-02-03T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-04T00:00:00.000Z"));
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:SimpleJodaTests.java

示例3: parse

import org.joda.time.MutableDateTime; //導入依賴的package包/類
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType().equals(DurationField.DAY_OF_WEEK)) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();

            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:22,代碼來源:SingleParser.java

示例4: parse

import org.joda.time.MutableDateTime; //導入依賴的package包/類
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType() == DurationField.DAY_OF_WEEK) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();

            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:22,代碼來源:StepParser.java

示例5: parse

import org.joda.time.MutableDateTime; //導入依賴的package包/類
@Override
public Set<Integer> parse(DateTime dateTime) {
    Set<Integer> set = new HashSet<>();
    if (getType().equals(DurationField.DAY_OF_MONTH)) {
        MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
        int maxDayOfMonth = mdt.getDayOfMonth();
        for (int i = 1; i <= maxDayOfMonth; i++) {
            set.add(i);
        }
    } else {
        int start = getRange().lowerEndpoint();
        int end = getRange().upperEndpoint();
        for (int i = start; i < end + 1; i++) {
            set.add(i);
        }
    }

    return set;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:20,代碼來源:AsteriskParser.java

示例6: parse

import org.joda.time.MutableDateTime; //導入依賴的package包/類
@Override
public Set<Integer> parse(DateTime dateTime) {
    if (getType().equals(DurationField.DAY_OF_WEEK)) {
        if (set != null) {
            Set<Integer> result = new HashSet<>();
            MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
            int maxDayOfMonth = mdt.getDayOfMonth();
            for (int i = 1; i <= maxDayOfMonth; i++) {
                mdt.setDayOfMonth(i);
                if (set.contains((mdt.getDayOfWeek() + 1) % 7)) {
                    result.add(mdt.getDayOfMonth());
                }
            }

            return result;
        }
    }

    return set;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:21,代碼來源:RangeParser.java

示例7: getTimeAfter

import org.joda.time.MutableDateTime; //導入依賴的package包/類
public List<DateTime> getTimeAfter(DateTime dateTime, int n) throws ParseException {
    if (n < 1) {
        throw new IllegalArgumentException("n should be > 0, but given " + n);
    }

    List<DateTime> list = null;
    MutableDateTime mdt = dateTime.toMutableDateTime();
    for (int i = 0; i < n; i++) {
        DateTime value = getTimeAfter(mdt.toDateTime());
        if (value != null) {
            if (list == null) {
                list = new ArrayList<>();
            }
            list.add(value);
            mdt.setMillis(value.getMillis());
        } else {
            break;
        }
    }

    return list;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:23,代碼來源:CronExpression.java

示例8: getTimeBefore

import org.joda.time.MutableDateTime; //導入依賴的package包/類
public List<DateTime> getTimeBefore(DateTime dateTime, int n) throws ParseException {
    if (n < 1) {
        throw new IllegalArgumentException("n should be > 0, but given " + n);
    }

    List<DateTime> list = null;
    MutableDateTime mdt = dateTime.toMutableDateTime();
    for (int i = 0; i < n; i++) {
        DateTime value = getTimeBefore(mdt.toDateTime());
        if (value != null) {
            if (list == null) {
                list = new ArrayList<>();
            }
            list.add(value);
            mdt.setMillis(value.getMillis());
        } else {
            break;
        }
    }

    return list;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:23,代碼來源:CronExpression.java

示例9: parse

import org.joda.time.MutableDateTime; //導入依賴的package包/類
@Override
public Set<Integer> parse(DateTime dateTime) {
    Set<Integer> result = new HashSet<>();
    if (index != -1) {
        MutableDateTime mdt = dateTime.dayOfMonth().withMaximumValue().toMutableDateTime();
        int maxDayOfMonth = mdt.getDayOfMonth();
        for (int i = 1; i <= maxDayOfMonth; i++) {
            mdt.setDayOfMonth(i);
            if (index == mdt.getDayOfWeek()) {
                result.add(mdt.getDayOfMonth());
            }
        }
    }

    return result;
}
 
開發者ID:stuxuhai,項目名稱:jcron,代碼行數:17,代碼來源:WeekAbbreviationParser.java

示例10: getIntervalStart

import org.joda.time.MutableDateTime; //導入依賴的package包/類
/**
 * Given an array of strings (a row from a {@link java.sql.ResultSet}) and the
 * {@link Granularity} used to make groupBy statements on time, it will parse out a {@link DateTime}
 * for the row which represents the beginning of the interval it was grouped on.
 *
 * @param offset the last column before the date fields.
 * @param recordValues  The results returned by Sql needed to read the time columns.
 * @param druidQuery  The original druid query which was made using calling
 * {@link #buildGroupBy(RelBuilder, Granularity, String)}.
 *
 * @return the datetime for the start of the interval.
 */
public DateTime getIntervalStart(int offset, String[] recordValues, DruidAggregationQuery<?> druidQuery) {
    List<SqlDatePartFunction> times = timeGrainToDatePartFunctions(druidQuery.getGranularity());

    DateTimeZone timeZone = getTimeZone(druidQuery);

    if (times.isEmpty()) {
        throw new UnsupportedOperationException("Can't parse dateTime for if no times were grouped on.");
    }

    MutableDateTime mutableDateTime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0, timeZone);

    for (int i = 0; i < times.size(); i++) {
        int value = Integer.parseInt(recordValues[offset + i]);
        SqlDatePartFunction fn = times.get(i);
        setDateTime(value, fn, mutableDateTime);
    }

    return mutableDateTime.toDateTime();
}
 
開發者ID:yahoo,項目名稱:fili,代碼行數:32,代碼來源:SqlTimeConverter.java

示例11: setDateTime

import org.joda.time.MutableDateTime; //導入依賴的package包/類
/**
 * Sets the correct part of a {@link DateTime} corresponding to a
 * {@link SqlDatePartFunction}.
 *
 * @param value  The value to be set for the dateTime with the sqlDatePartFn
 * @param sqlDatePartFn  The function used to extract part of a date with sql.
 * @param dateTime  The original dateTime to create a copy of.
 */
protected void setDateTime(int value, SqlDatePartFunction sqlDatePartFn, MutableDateTime dateTime) {
    if (YEAR.equals(sqlDatePartFn)) {
        dateTime.setYear(value);
    } else if (MONTH.equals(sqlDatePartFn)) {
        dateTime.setMonthOfYear(value);
    } else if (WEEK.equals(sqlDatePartFn)) {
        dateTime.setWeekOfWeekyear(value);
        dateTime.setDayOfWeek(1);
    } else if (DAYOFYEAR.equals(sqlDatePartFn)) {
        dateTime.setDayOfYear(value);
    } else if (HOUR.equals(sqlDatePartFn)) {
        dateTime.setHourOfDay(value);
    } else if (MINUTE.equals(sqlDatePartFn)) {
        dateTime.setMinuteOfHour(value);
    } else if (SECOND.equals(sqlDatePartFn)) {
        dateTime.setSecondOfMinute(value);
    } else {
        throw new IllegalArgumentException("Can't set value " + value + " for " + sqlDatePartFn);
    }
}
 
開發者ID:yahoo,項目名稱:fili,代碼行數:29,代碼來源:SqlTimeConverter.java

示例12: getLowerDateTimeBound

import org.joda.time.MutableDateTime; //導入依賴的package包/類
public static DateTime getLowerDateTimeBound(String dateRange) throws ParseException {
    Range range = SearchExpressionUtils.parseRange(dateRange);
    if (range == null) {
        throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange);
    }
    if (range.getLowerBoundValue() != null) {
        java.util.Date lowerRangeDate = null;
        try{
            lowerRangeDate = CoreApiServiceLocator.getDateTimeService().convertToDate(range.getLowerBoundValue());
        }catch(ParseException pe){
            GlobalVariables.getMessageMap().putError("dateFrom", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage());
        }
        MutableDateTime dateTime = new MutableDateTime(lowerRangeDate);
        dateTime.setMillisOfDay(0);
        return dateTime.toDateTime();
    }
    return null;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:19,代碼來源:DocumentSearchInternalUtils.java

示例13: getUpperDateTimeBound

import org.joda.time.MutableDateTime; //導入依賴的package包/類
public static DateTime getUpperDateTimeBound(String dateRange) throws ParseException {
    Range range = SearchExpressionUtils.parseRange(dateRange);
    if (range == null) {
        throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange);
    }
    if (range.getUpperBoundValue() != null) {
        java.util.Date upperRangeDate = null;
        try{
            upperRangeDate = CoreApiServiceLocator.getDateTimeService().convertToDate(range.getUpperBoundValue());
        }catch(ParseException pe){
            GlobalVariables.getMessageMap().putError("dateCreated", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage());
        }
        MutableDateTime dateTime = new MutableDateTime(upperRangeDate);
        // set it to the last millisecond of the day
        dateTime.setMillisOfDay((24 * 60 * 60 * 1000) - 1);
        return dateTime.toDateTime();
    }
    return null;
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:20,代碼來源:DocumentSearchInternalUtils.java

示例14: doEvaluate

import org.joda.time.MutableDateTime; //導入依賴的package包/類
@Override
protected void doEvaluate(TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output)
{
    int date = inputs.get(0).getInt32();
    long ymd[] = MDateAndTime.decodeDate(date);
    int mode = getMode(context, inputs);
    if (!MDateAndTime.isValidDateTime(ymd, ZeroFlag.YEAR) || mode < 0)
    {
        context.warnClient(new InvalidDateFormatException("Invalid DATE value " , date + ""));
        output.putNull();
    }
    else
    {
        output.putInt32(modes[(int) mode].getYearWeek(new MutableDateTime(DateTimeZone.forID(context.getCurrentTimezone())),
                                                      (int)ymd[0], (int)ymd[1], (int)ymd[2]));
    }
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:18,代碼來源:MYearWeek.java

示例15: apply

import org.joda.time.MutableDateTime; //導入依賴的package包/類
@Override Val apply( Env env, Env.StackHelp stk, AST asts[] ) {
  Val val = asts[1].exec(env);
  switch( val.type() ) {
  case Val.NUM: 
    double d = val.getNum();
    return new ValNum(Double.isNaN(d) ? d : op(new MutableDateTime(0),d));
  case Val.FRM: 
    Frame fr = stk.track(val).getFrame();
    if( fr.numCols() > 1 ) throw water.H2O.unimpl();
    return new ValFrame(new MRTask() {
        @Override public void map( Chunk chk, NewChunk cres ) {
          MutableDateTime mdt = new MutableDateTime(0,ParseTime.getTimezone());
          for( int i=0; i<chk._len; i++ )
            cres.addNum(chk.isNA(i) ? Double.NaN : op(mdt,chk.at8(i)));
        }
      }.doAll_numericResult(1,fr).outputFrame(fr._names, factors()));
  default: throw water.H2O.fail();
  }
}
 
開發者ID:kyoren,項目名稱:https-github.com-h2oai-h2o-3,代碼行數:20,代碼來源:ASTTime.java


注:本文中的org.joda.time.MutableDateTime類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。