当前位置: 首页>>代码示例>>Java>>正文


Java GregorianCalendar.getInstance方法代码示例

本文整理汇总了Java中java.util.GregorianCalendar.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.getInstance方法的具体用法?Java GregorianCalendar.getInstance怎么用?Java GregorianCalendar.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.GregorianCalendar的用法示例。


在下文中一共展示了GregorianCalendar.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getScheduleETA

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private static long getScheduleETA(String exportTime) {
  Calendar toCal = GregorianCalendar.getInstance();
  toCal.setTime(new Date());
  LocalDateUtil.resetTimeFields(toCal);
  // Get hour/min.
  String[] timeOfDay = exportTime.split(":");
  try {
    toCal.set(Calendar.SECOND, 0);
    toCal.set(Calendar.MILLISECOND, 0);
    if (timeOfDay.length >= 1) {
      toCal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeOfDay[0]));
    }
    if (timeOfDay.length == 2) {
      toCal.set(Calendar.MINUTE, Integer.parseInt(timeOfDay[1]));
    }
    xLogger.fine("toCal: {0}", toCal.toString());
  } catch (NumberFormatException e) {
    xLogger.warn("Invalid number for hour or minute in {0}", exportTime);
  }
  return toCal.getTimeInMillis();
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:22,代码来源:CustomReportsExportMgr.java

示例2: onCreate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_time_selection);

    Bundle extras = getIntent().getExtras();
    setTitle(extras.getInt("title"));
    //noinspection ConstantConditions
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, extras.getInt("color"))));

    dtpTime = (TimePicker) findViewById(R.id.timePicker);
    dtpTime.setIs24HourView(true);
    timeSelection = GregorianCalendar.getInstance();
    timeSelection.setTimeInMillis(extras.getLong("date"));
    //noinspection deprecation
    dtpTime.setCurrentHour(timeSelection.get(Calendar.HOUR_OF_DAY));
    //noinspection deprecation
    dtpTime.setCurrentMinute(timeSelection.get(Calendar.MINUTE));
}
 
开发者ID:Baleine82,项目名称:TrainPonctuality,代码行数:20,代码来源:TimeSelectionActivity.java

示例3: Test4061476

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void Test4061476() {
    SimpleDateFormat fmt = new SimpleDateFormat("ddMMMyy", Locale.UK);
    Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"),
            Locale.UK);
    fmt.setCalendar(cal);
    try {
        Date date = fmt.parse("29MAY97");
        cal.setTime(date);
    } catch (Exception e) {
    }
    cal.set(HOUR_OF_DAY, 13);
    logln("Hour: " + cal.get(HOUR_OF_DAY));
    cal.add(HOUR_OF_DAY, 6);
    logln("Hour: " + cal.get(HOUR_OF_DAY));
    if (cal.get(HOUR_OF_DAY) != 19) {
        errln("Fail: Want 19 Got " + cal.get(HOUR_OF_DAY));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:CalendarRegression.java

示例4: getTimestampString

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static String getTimestampString(Date date) {
    String timpstamp = null;
    long time = date.getTime();
    if (isSameDay(time)) {
        Calendar calendar = GregorianCalendar.getInstance();
        calendar.setTime(date);
        int hours = calendar.get(11);
        if (hours > 17) {
            timpstamp = "晚上 hh:mm";
        } else if (hours >= 0 && hours <= 6) {
            timpstamp = "凌晨 hh:mm";
        } else if (hours > 11 && hours <= 17) {
            timpstamp = "下午 hh:mm";
        } else {
            timpstamp = "上午 hh:mm";
        }
    } else if (isYesterday(time)) {
        timpstamp = "昨天 HH:mm";
    } else {
        timpstamp = "M月d日 HH:mm";
    }

    return (new SimpleDateFormat(timpstamp, Locale.CHINA)).format(date);
}
 
开发者ID:xingjiyuan,项目名称:AndroidStatisticsLib,代码行数:25,代码来源:DateUtils.java

示例5: setReadyForNext

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void setReadyForNext(String readyForNext) {
    Calendar cal = GregorianCalendar.getInstance();
    String s= readyForNext.replace("Z","+00:00");
    Date date =null;
    try {
        date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parse(s);

    } catch (ParseException e) {
        e.printStackTrace();
    }
    this.readyForNextAction = date;
}
 
开发者ID:TudorRosca,项目名称:enklave,代码行数:13,代码来源:InformationProfile.java

示例6: createObjectFromJson_primitiveList_mixedValues

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Test
public void createObjectFromJson_primitiveList_mixedValues() throws JSONException, IOException {
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_STRING_LIST, new String[] {"a", null, "bc"});
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_BOOLEAN_LIST, new Boolean[] {true, null, false});
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_DOUBLE_LIST, new Double[] {1.0d, null, 2.0d});
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_FLOAT_LIST, new Float[] {1.0f, null, 2.0f});
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_BYTE_LIST, new Byte[] {1, null, 2});
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_SHORT_LIST, new Short[] {1, null, 2});
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_INT_LIST, new Integer[] {1, null, 2});
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_LONG_LIST, new Long[] {1L, null, 2L});

    // Date as integer
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_DATE_LIST,
            new Integer[] {0, null, 1},
            new Date[] {new Date(0), null, new Date(1)});
    // Date as String
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_DATE_LIST,
            new String [] {"/Date(1000)/", null, "/Date(2000)/"},
            new Date[] {new Date(1000), null, new Date(2000)});
    // Date as String timezone
    // Oct 03 2015 14:45.33
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("Australia/West"));
    cal.set(2015, Calendar.OCTOBER, 3, 14, 45, 33);
    cal.set(Calendar.MILLISECOND, 376);
    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_DATE_LIST,
            new String [] {"/Date(1443854733376+0800)/", null},
            new Date[] {cal.getTime(), null});


    testPrimitiveListWithValues(PrimitiveListTypes.FIELD_BINARY_LIST,
            new String[] {new String(Base64.encode(new byte[] {1, 2, 3}, Base64.DEFAULT), UTF_8),
                    null, new String(Base64.encode(new byte[] {4, 5, 6}, Base64.DEFAULT), UTF_8)},
            new byte[][] {new byte[]{1, 2, 3}, null, new byte[]{4, 5, 6}});
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:RealmJsonTests.java

示例7: setFechaNacimiento

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void setFechaNacimiento(Date fechaNacimiento)
		throws CitizenException {
	Calendar calendar = GregorianCalendar.getInstance();
	try {
		if (fechaNacimiento.before(calendar.getTime()))
			this.fechaNacimiento = fechaNacimiento;
		else
			throw new CitizenException(
					"La fecha de nacimiento es posterior al dia actual.");
	} catch (NullPointerException e) {
		throw new CitizenException(
				"La fecha de nacimiento no puede ser null.");
	}
}
 
开发者ID:Arquisoft,项目名称:citizensLoader4b,代码行数:15,代码来源:Citizen.java

示例8: buildRRTChartModel

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public List<FChartModel> buildRRTChartModel(ReportData r, String repGenTime) {
  Iterator<? extends ISlice> it = r.getResults().iterator();
  ISlice nextSlice = null;
  if (it.hasNext()) {
    nextSlice = it.next();
  }
  List<FChartModel> models = new ArrayList<FChartModel>(r.getResults().size());
  while (nextSlice != null) {
    IReportsSlice monthSlice = (IReportsSlice) nextSlice;
    FChartModel model = new FChartModel();
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTime(nextSlice.getDate());
    model.repGenTime = repGenTime;
    model.label =
        cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal
            .get(Calendar.DAY_OF_MONTH);
    List<String> value = new ArrayList<String>();
    value.add(NumberUtil.getFormattedValue(monthSlice.getAverageStockoutResponseTime()));
    value
        .add(NumberUtil.getFormattedValue(monthSlice.getAverageLessThanMinResponseTimeAverage()));
    value.add(NumberUtil.getFormattedValue(monthSlice.getAverageMoreThanMaxResponse()));
    model.value = value;
    models.add(model);
    if (it.hasNext()) {
      nextSlice = it.next();
    } else {
      nextSlice = null;
    }
  }
  return models;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:32,代码来源:FChartBuilder.java

示例9: resetTimeFields

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static Calendar resetTimeFields(Calendar cal, String timezone) {
  if (timezone != null) {
    Calendar newcal = GregorianCalendar.getInstance(TimeZone.getTimeZone(timezone));
    newcal.setTime(cal.getTime());
    cal = newcal;
  }
  return resetTimeFields(cal);
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:9,代码来源:LocalDateUtil.java

示例10: doUpdateInsertDeleteWaehler

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * @param p_connection
 * @throws SQLException
 */
private static void doUpdateInsertDeleteWaehler(Connection p_connection)
throws SQLException {

    System.out.println("UPDATE WAEHLER START ...");

    PreparedStatement p = p_connection.prepareStatement(
        "UPDATE WAEHLER SET AUSTRITTSDATUM=? WHERE NAME=?");

    p.setDate(1, null);
    p.setString(2, "Muster1");
    p.execute();
    p.close();
    System.out.println("END UPDATE WAEHLER");
    System.out.println("INSERT INTO WAEHLER START ...");

    p = p_connection.prepareStatement(
        "INSERT INTO WAEHLER (NAME, AUSTRITTSDATUM) VALUES (?,?)");

    Calendar cal = GregorianCalendar.getInstance();

    p.setString(1, "Muster3");
    p.setDate(2, new Date(cal.getTimeInMillis()), cal);
    p.execute();
    p.close();
    System.out.println("END INSERT INTO WAEHLER");
    System.out.println("DELETE FROM WAEHLER START ...");

    p = p_connection.prepareStatement(
        "DELETE FROM WAEHLER WHERE NAME = ?");

    p.setString(1, "Muster2");
    p.execute();
    p.close();
    System.out.println("END DELETE FROM WAEHLER");
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:40,代码来源:TestKarl.java

示例11: buildTCChartModel

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public List<FChartModel> buildTCChartModel(ReportData r, String repGenTime) {
  Iterator<? extends ISlice> it = r.getResults().iterator();
  ISlice nextSlice = null;
  if (it.hasNext()) {
    nextSlice = it.next();
  }
  List<FChartModel> models = new ArrayList<FChartModel>(r.getResults().size());
  Calendar prevCal = null;
  Counts counts = new Counts();

  while (nextSlice != null) {
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTime(nextSlice.getDate());
    if (prevCal == null || LocalDateUtil.compareDates(cal, prevCal) == 0) {
      aggregateCounts(counts, nextSlice);
      prevCal = cal;
    } else {
      models.add(getFChartModel(counts, prevCal, repGenTime));
      counts = new Counts();
      aggregateCounts(counts, nextSlice);
      prevCal = cal;
    }
    if (it.hasNext()) {
      nextSlice = it.next();
    } else {
      models.add(getFChartModel(counts, cal, repGenTime));
      nextSlice = null;
    }
  }
  return models;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:32,代码来源:FChartBuilder.java

示例12: setSendTime

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Set the send time
 *
 * @param model- Transaction model
 * @param value- parsed value
 */
private void setSendTime(SMSTransactionModel model, String value) {
  Calendar calendar = GregorianCalendar.getInstance();
  final long sendTime = Long.parseLong(value) * SMSConstants.MILLISECONDS;
  if (sendTime > calendar.getTimeInMillis()) {
    //send time cannot be a future time
    throw new BadRequestException("M016");
  }
  model.setSendTime(sendTime);
  if (model.getActualTransactionDate() != null) {
    model.setActualTransactionDate(model.getSendTime() - model.getActualTransactionDate());
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:19,代码来源:SMSBuilder.java

示例13: createTimestamp

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static Date createTimestamp(Date t) {
  Calendar cal = GregorianCalendar.getInstance();
  cal.setTime(t);
  cal.set(Calendar.DATE, 1); // reset date to the first of the month
  LocalDateUtil.resetTimeFields(cal);
  return cal.getTime();
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:8,代码来源:MonthSlice.java

示例14: createActiveCountsStatsStoreKey

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static String createActiveCountsStatsStoreKey(Long domainId, Date d, String objectType,
                                                     String objectId, String dt, String dv) {
  MessageDigest md = null;
  if (d != null && domainId != null && objectType != null && objectId != null && dt != null
      && dv != null) {
    try {
      // Get the time string
      Calendar cal = GregorianCalendar.getInstance();
      cal.setTime(d);
      String timeStr = String.valueOf(cal.get(Calendar.DATE)) +
          String.valueOf(cal.get(Calendar.MONTH)) +
          String.valueOf(cal.get(Calendar.YEAR));
      md = MessageDigest.getInstance("MD5");
      md.update(timeStr.getBytes()); // date
      md.update(domainId.toString().getBytes()); // domain Id
      md.update(objectType.getBytes()); // object type
      md.update(objectId.getBytes()); // object Id
      md.update(dt.getBytes()); // dim. type
      md.update(dv.getBytes()); // dim. value
    } catch (NoSuchAlgorithmException e) {
      XLog.getLog(Slice.class).warn("Exception: No such algorithm: {0}", e.getMessage());
    }
  }
  if (md != null) {
    byte[] bytes = md.digest();
    if (bytes != null) {
      return new String(Hex.encodeHex(bytes));
    }
  }
  return null;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:32,代码来源:JDOUtils.java

示例15: getSlices

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Results getSlices(String frequency, Date from, Date until, String objectType,
                                String objectId, String dimType, String dimValue,
                                PageParams pageParams) {
  if (from == null || objectType == null || dimType == null || dimValue == null) {
    throw new IllegalArgumentException(
        "At least start date, object type, dim. type and dim. value should be present");
  }
  boolean isFreqDaily = (ReportsConstants.FREQ_DAILY.equals(frequency));
  // Determine the model to be queried, and query filters
  Class<? extends ISlice> clazz = JDOUtils.getImplClass(IMonthSlice.class);
  if (isFreqDaily) {
    clazz = JDOUtils.getImplClass(IDaySlice.class);
  }
  // Get the dates set correctly
  Calendar cal = GregorianCalendar.getInstance();
  cal.setTime(from);
  LocalDateUtil.resetTimeFields(cal);
  Date fromDate = cal.getTime();
  if (until == null) {
    cal.setTime(new Date());
  } else {
    cal.setTime(until);
  }
  LocalDateUtil.resetTimeFields(cal);
  Date untilDate = cal.getTime();
  // Update the filters
  String queryFilters = "oty == otyParam && dt == dtParam && dv == dvParam && d > fromParam";
  String
      declarations =
      " PARAMETERS String otyParam, String dtParam, String dvParam, Date fromParam";
  Map<String, Object> params = new HashMap<String, Object>();
  params.put("otyParam", objectType);
  params.put("dtParam", dimType);
  params.put("dvParam", dimValue);
  params.put("fromParam", LocalDateUtil.getOffsetDate(fromDate, -1, Calendar.MILLISECOND));
  if (untilDate != null) {
    queryFilters += " && d < untilParam";
    declarations += ", Date untilParam";
    params.put("untilParam", untilDate);
  }
  if (objectId != null) {
    queryFilters += " && oId == oIdParam";
    declarations += ", String oIdParam";
    params.put("oIdParam", objectId);
  }
  // Form query
  PersistenceManager pm = PMF.get().getPersistenceManager();
  List<? extends ISlice> results = null;
  String cursor = null;
  // Form query
  String
      queryStr =
      "SELECT FROM " + clazz.getName() + " WHERE " + queryFilters + declarations
          + " import java.util.Date; ORDER BY d DESC";
  // Execute query
  Query q = pm.newQuery(queryStr);
  if (pageParams != null) {
    QueryUtil.setPageParams(q, pageParams);
  }
  try {
    results = (List<? extends ISlice>) q.executeWithMap(params);
    if (results != null) {
      results.size();
      cursor = QueryUtil.getCursor(results);
      results = (List<? extends ISlice>) pm.detachCopyAll(results);
    }
  } finally {
    try {
      q.closeAll();
    } catch (Exception ignored) {

    }
    pm.close();
  }
  return new Results(results, cursor);
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:78,代码来源:ReportsUtil.java


注:本文中的java.util.GregorianCalendar.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。