Java 类java.util.GregorianCalendar 实例源码

项目:oscm    文件:ResellerShareResultAssembler.java   
private Period preparePeriod(long periodStartTime, long periodEndTime)
        throws DatatypeConfigurationException {

    Period period = new Period();

    DatatypeFactory df = DatatypeFactory.newInstance();
    GregorianCalendar gc = new GregorianCalendar();

    // start date
    period.setStartDate(BigInteger.valueOf(periodStartTime));
    gc.setTimeInMillis(periodStartTime);
    period.setStartDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    // end date
    period.setEndDate(BigInteger.valueOf(periodEndTime));
    gc.setTimeInMillis(periodEndTime);
    period.setEndDateIsoFormat(df.newXMLGregorianCalendar(gc).normalize());

    return period;
}
项目:lams    文件:TimeUtil.java   
final static Date fastDateCreate(int year, int month, int day, Calendar targetCalendar) {

        Calendar dateCal = (targetCalendar == null) ? new GregorianCalendar() : targetCalendar;

        synchronized (dateCal) {
            java.util.Date origCalDate = dateCal.getTime();
            try {
                dateCal.clear();

                // why-oh-why is this different than java.util.date, in the year part, but it still keeps the silly '0' for the start month????
                dateCal.set(year, month - 1, day, 0, 0, 0);
                dateCal.set(Calendar.MILLISECOND, 0);

                long dateAsMillis = dateCal.getTimeInMillis();

                return new Date(dateAsMillis);
            } finally {
                dateCal.setTime(origCalDate);
            }
        }
    }
项目:Assignment_1    文件:FilteringPlaceTest.java   
/**
 * There is no assert equals because everything depends of the user input.
 * If the user input a good data so, the programe keep runing, else, we created an exception.
 */
@Test
public void testFilteringBy() {
    GregorianCalendar date = new GregorianCalendar(2017, 8, 12, 22, 00, 10);
    EarthCoordinate earth = new EarthCoordinate(100.0, 34.0, 890.0);
    Wifi wifi = new Wifi(date, "easyId", earth, "easyName", "easyMac", 5000, -90);
    ArrayList<Wifi> array = new ArrayList<Wifi>();
    array.add(wifi);
    FilteringPlace filter = new FilteringPlace();
    try {
        filter.filteringBy(array);
    } 
    catch (InputException ex) {
        ex.printStackTrace();
    }
}
项目:parabuild-ci    文件:DayTests.java   
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Day d = new Day(4, 5, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    assertEquals(989017199999L, d.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        d.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
项目:parabuild-ci    文件:WeekTests.java   
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Week w = new Week(52, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    assertEquals(1009756799999L, w.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        w.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
项目:Hands-On-Android-UI-Development    文件:AllowanceOverviewPresenter.java   
Pair<Date, Date> getToday() {
    final GregorianCalendar today = new GregorianCalendar();
    today.set(Calendar.HOUR_OF_DAY, today.getActualMaximum(Calendar.HOUR_OF_DAY));
    today.set(Calendar.MINUTE, today.getActualMaximum(Calendar.MINUTE));
    today.set(Calendar.SECOND, today.getActualMaximum(Calendar.SECOND));
    today.set(Calendar.MILLISECOND, today.getActualMaximum(Calendar.MILLISECOND));

    final Date end = today.getTime();
    today.add(Calendar.DATE, -1);
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    return new Pair<>(today.getTime(), end);
}
项目:MFM    文件:Debug.java   
public void out(String output) {
    if (listBool) {
        list.add("[" + sdateFormat.format(new GregorianCalendar().getTime()) + "] " + output);
    } else {
        writer.println("[" + sdateFormat.format(new GregorianCalendar().getTime()) + "] " + output);
    }
}
项目:LightSIP    文件:SIPDate.java   
/**
 * convert the SIP Date of this structure to a Java Date.
 * SIP Dates are forced to be GMT. Stores the converted time
 * as a java Calendar class.
 */
private void setJavaCal() {
    javaCal =
        new GregorianCalendar(
            TimeZone.getTimeZone("GMT:0"),
            Locale.getDefault());
    if (year != -1)
        javaCal.set(Calendar.YEAR, year);
    if (day != -1)
        javaCal.set(Calendar.DAY_OF_MONTH, day);
    if (month != -1)
        javaCal.set(Calendar.MONTH, month);
    if (wkday != -1)
        javaCal.set(Calendar.DAY_OF_WEEK, wkday);
    if (hour != -1)
        javaCal.set(Calendar.HOUR, hour);
    if (minute != -1)
        javaCal.set(Calendar.MINUTE, minute);
    if (second != -1)
        javaCal.set(Calendar.SECOND, second);
}
项目:BigQueryStudy    文件:App.java   
static public String writeSalesOrder(Integer rowCount){
    // prepare linses content 
    List<String> lines = new ArrayList<String>();
    for(int i = 0; i < rowCount; i++){
        String product = "product " + i / 1000;
        BigDecimal product_price = (new BigDecimal(i/1000)).multiply(new BigDecimal(100));
    JSONObject salesOrder = SalesOrderHelper.createOneSalesOrderRow("1", "1", product, product_price.toString(), "1", "michael", "han", "1", "QAD", "1", "HP", "open", Long.toString(new GregorianCalendar().getTimeInMillis()), "001");
    lines.add(salesOrder.toString());
    }

    // prepare file system by a given filename
    String fileName = "SalesOrder_" + rowCount.toString() + ".json";
    String filePath = FileSystems.getDefault().getPath("").toAbsolutePath() + "/" + fileName;
    File newFile = new File(filePath);
    try {
    newFile.createNewFile();
} catch (IOException e) {
    e.printStackTrace();
}
    FileWriterHelper.writeStringToFile(newFile.toPath(), lines, false);

    System.out.println("A json file with records[" + rowCount + "] :" + filePath);
    return filePath;
  }
项目:GitHub    文件:RealmJsonTests.java   
@Test
public void createObjectFromJson_dateAsStringTimeZone() throws JSONException {
    // Oct 03 2015 14:45.33
    JSONObject json = new JSONObject();
    json.put("columnDate", "/Date(1443854733376+0800)/");

    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, json);
    realm.commitTransaction();

    AllTypes obj = realm.where(AllTypes.class).findFirst();
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("Australia/West"));
    cal.set(2015, Calendar.OCTOBER, 03, 14, 45, 33);
    cal.set(Calendar.MILLISECOND, 376);
    Date convDate = obj.getColumnDate();

    assertEquals(convDate.getTime(), cal.getTimeInMillis());
}
项目:CalendarFX    文件:DateIteratorFactory.java   
static DateValue dateToDateValue(Date date, boolean midnightAsDate) {
    GregorianCalendar c = new GregorianCalendar(TimeUtils.utcTimezone());
    c.setTime(date);
    int h = c.get(Calendar.HOUR_OF_DAY),
            m = c.get(Calendar.MINUTE),
            s = c.get(Calendar.SECOND);
    if (midnightAsDate && 0 == (h | m | s)) {
        return new DateValueImpl(c.get(Calendar.YEAR),
                c.get(Calendar.MONTH) + 1,
                c.get(Calendar.DAY_OF_MONTH));
    } else {
        return new DateTimeValueImpl(c.get(Calendar.YEAR),
                c.get(Calendar.MONTH) + 1,
                c.get(Calendar.DAY_OF_MONTH),
                h,
                m,
                s);
    }
}
项目:citizensLoader4b    文件:Citizen.java   
private String generarPassword()
        throws NoSuchAlgorithmException, CitizenException {
    String password = "";
    Calendar calendar = GregorianCalendar.getInstance();
    Random r = new Random(calendar.getTimeInMillis());
    int i = 0;

    while (i < 10) {
        char c = (char) r.nextInt(255);
        if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')
                || (c >= 'a' && c <= 'z')) {
            password += c;
            i++;
        }
    }

    return new EncryptMD5().encrypting(password);
}
项目:SER316-Munich    文件:EventImpl.java   
/**
   * @see net.sf.memoranda.Event#getTime()
   */
  public Date getTime() {
    //Deprecated methods
//Date d = new Date();
//d.setHours(getHour());
//d.setMinutes(getMinute());
//d.setSeconds(0);
//End deprecated methods

Date d = new Date(); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
Calendar calendar = new GregorianCalendar(Local.getCurrentLocale()); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
calendar.setTime(d); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
calendar.set(Calendar.HOUR_OF_DAY, getHour()); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
calendar.set(Calendar.MINUTE, getMinute()); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
calendar.set(Calendar.SECOND, 0); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
d = calendar.getTime(); //Revision to fix deprecated methods (jcscoobyrs) 12-NOV-2003 14:26:00
      return d;
  }
项目:alfresco-repository    文件:FreeMarkerModelLuceneFunctionTest.java   
/**
 * Test generation of lucene date ranges
 *
 */
public void testLuceneDateRangeFunctionToDate()
{
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 2001);
    cal.set(Calendar.MONTH, 1);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    String isoStartDate = ISO8601DateFormat.format(cal.getTime());
    cal.add(Calendar.DAY_OF_MONTH, 4);
    String isoEndDate = ISO8601DateFormat.format(cal.getTime());
    String template = "${luceneDateRange(\""+isoStartDate+"\", \""+isoEndDate+"\")}";
    FreeMarkerWithLuceneExtensionsModelFactory mf = new FreeMarkerWithLuceneExtensionsModelFactory();
    mf.setServiceRegistry(serviceRegistry);
    String result = serviceRegistry.getTemplateService().processTemplateString("freemarker", template, mf.getModel());
    assertEquals(result, "["+isoStartDate+" TO "+isoEndDate+"]");
}
项目:parabuild-ci    文件:MillisecondTests.java   
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithCalendar() {
    Millisecond m = new Millisecond(500, 55, 40, 2, 15, 4, 2000);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    assertEquals(955762855500L, m.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        m.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
项目:jdk8u-jdk    文件:XMLFormatterDate.java   
/**
 * Before the fix, JDK8 prints: {@code
 * <record>
 *   <date>3913-11-18T17:35:40</date>
 *   <millis>1384792540403</millis>
 *   <sequence>0</sequence>
 *   <level>INFO</level>
 *   <thread>1</thread>
 *   <message>test</message>
 * </record>
 * }
 * After the fix, it should print: {@code
 * <record>
 *   <date>2013-11-18T17:35:40</date>
 *   <millis>1384792696519</millis>
 *   <sequence>0</sequence>
 *   <level>INFO</level>
 *   <thread>1</thread>
 *   <message>test</message>
 * </record>
 * }
 * @param args the command line arguments
 */
public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    try {
        Locale.setDefault(Locale.ENGLISH);

        final GregorianCalendar cal1 = new GregorianCalendar();
        final int year1 = cal1.get(Calendar.YEAR);

        LogRecord record = new LogRecord(Level.INFO, "test");
        XMLFormatter formatter = new XMLFormatter();
        final String formatted = formatter.format(record);
        System.out.println(formatted);

        final GregorianCalendar cal2 = new GregorianCalendar();
        final int year2 = cal2.get(Calendar.YEAR);
        if (year2 < 1900) {
            throw new Error("Invalid system year: " + year2);
        }

        StringBuilder buf2 = new StringBuilder()
                .append("<date>").append(year2).append("-");
        if (!formatted.contains(buf2.toString())) {
            StringBuilder buf1 = new StringBuilder()
                    .append("<date>").append(year1).append("-");
            if (formatted.contains(buf1)
                    && year2 == year1 + 1
                    && cal2.get(Calendar.MONTH) == Calendar.JANUARY
                    && cal2.get(Calendar.DAY_OF_MONTH) == 1) {
                // Oh! The year just switched in the midst of the test...
                System.out.println("Happy new year!");
            } else {
                throw new Error("Expected year " + year2
                        + " not found in log:\n" + formatted);
            }
        }
    } finally {
        Locale.setDefault(locale);
    }
}
项目:parabuild-ci    文件:HourTests.java   
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Hour h = new Hour(21, 21, 4, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    assertEquals(987886799999L, h.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        h.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
项目:TechnicalAnalysisTool    文件:DateUtilTest.java   
/**
 * Test of isPublicHoliday method, of class DateUtil.
 */
@Test
public void testIsPublicHoliday() {
    System.out.println("isPublicHoliday");
    String countryName = "Australia";
    Calendar date1 = new GregorianCalendar(2010, 3, 2, 0, 0, 0); //Yes
    assertTrue(DateUtil.isPublicHoliday(date1, countryName));

    Calendar date2 = new GregorianCalendar(2017, 9, 11, 0, 0, 0); //Yes
    assertFalse(DateUtil.isPublicHoliday(date2, countryName));

    Calendar date3 = new GregorianCalendar(2017, 9, 12, 0, 0, 0); //Yes
    assertFalse(DateUtil.isPublicHoliday(date3, countryName));
}
项目:saladium    文件:FlatXmlBuilder.java   
/**
 * Ajoute ou retire un jour à la date.
 * @param date La date à modifier.
 * @param value la valeur de l'incrément.
 * @return La date modifiée.
 */
protected Date addDay(Date date, Integer value) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    gc.add(GregorianCalendar.DAY_OF_MONTH, value);
    return gc.getTime();
}
项目:jetfuel    文件:AdapterTests.java   
@Test
public void dateYMDio() {
    DateAdapter adapter = new DateAdapter("yyyyMMdd");
    Date date = adapter.parse("20161231");
    Assert.assertTrue(date.getTime() == new GregorianCalendar(2016, 11, 31).getTimeInMillis());
    String formatted = adapter.format(date);
    Assert.assertTrue("20161231".equals(formatted));
}
项目:css-elasticsearch    文件:DateUtil.java   
/**
 * <pre>
 * 描述:间隔指定分钟后日期(例如:每30分钟)
 * 作者:ZhangYi
 * 时间:2016年5月5日 下午4:29:07
 * 参数:(参数列表)
 * @param dateTime  指定日期
 * @param interval  间隔分钟
 * @return
 * </pre>
 */
public static Date handleDateTimeByMinute(Date dateTime, int interval) {
    try {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(dateTime);
        calendar.add(Calendar.MINUTE, interval);
        dateTime = calendar.getTime();
    } catch (Exception e) {
        logger.error("--间隔指定分钟后日期异常!", e);
    }
    return dateTime;
}
项目:amap    文件:MIP_CalendarUtil2.java   
public String getCurrentYearFirst()
{
    int yearPlus = this.getYearPlus();
    GregorianCalendar currentDate = new GregorianCalendar();
    currentDate.add(GregorianCalendar.DATE, yearPlus);
    Date yearDay = currentDate.getTime();
    DateFormat df = DateFormat.getDateInstance();
    String preYearDay = df.format(yearDay);
    return preYearDay;
}
项目:Hands-On-Android-UI-Development    文件:DatePickerWrapper.java   
@Override
public void onDateSet(
        final DatePicker view,
        final int year,
        final int month,
        final int dayOfMonth) {

    setDate(new GregorianCalendar(year, month, dayOfMonth).getTime());
}
项目:homebank_android    文件:HbCompat.java   
public static long dateToJulian(Date date) {

        GregorianCalendar calendarDate = new GregorianCalendar();
        calendarDate.setTime(date);

        Calendar calendarBegin = new GregorianCalendar(1, GregorianCalendar.JANUARY, 1);

        long millisecondsDate = calendarDate.getTimeInMillis();
        long millisecondsBegin = calendarBegin.getTimeInMillis();
        long diff = millisecondsDate - millisecondsBegin;
        long diffDays = diff / (24 * 60 * 60 * 1000) - 1;

        return diffDays;
    }
项目:ats-framework    文件:TestWithReturnValuesClass.java   
@Action(name = "TestWithReturnValuesClass call3")
public List<Calendar> call3() {

    List<Calendar> list = new ArrayList<Calendar>();
    list.add( new GregorianCalendar() );
    return list;
}
项目:oscm    文件:PlatformUserIT.java   
private void doTestUserWithoutOrganization()
        throws NonUniqueBusinessKeyException {
    PlatformUser usr1 = new PlatformUser();
    usr1.setAddress("Address1");
    usr1.setCreationDate(GregorianCalendar.getInstance().getTime());
    usr1.setEmail("EMail1");
    usr1.setFirstName("Angela");
    usr1.setLastName("Merkel");
    usr1.setUserId("angela");
    usr1.setPhone("111111/111111");
    usr1.setStatus(UserAccountStatus.ACTIVE);
    usr1.setPasswordRecoveryStartDate(1360046301085L);
    mgr.persist(usr1);
}
项目:homebank_android    文件:HbCompat.java   
public static Date julianToDate(long date) {
    GregorianCalendar calendarBegin = new GregorianCalendar(1, GregorianCalendar.JANUARY, 1);
    long millisecondsBegin = calendarBegin.getTimeInMillis();

    long diff = date * (24 * 60 * 60 * 1000);
    long millisecondsDate = diff + millisecondsBegin;
    int days = (int) (millisecondsDate / (24 * 60 * 60 * 1000));

    GregorianCalendar calendarDate = new GregorianCalendar();
    calendarDate.setTimeInMillis(0);
    calendarDate.add(GregorianCalendar.DAY_OF_MONTH, days + 1);//todo : why +1 ?

    return calendarDate.getTime();
}
项目:GongXianSheng    文件:TimeUtils.java   
public static String getPerWeekEnd() {
    Date date = new Date();
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    int dayInWeek = calendar.get(Calendar.DAY_OF_WEEK);
    //本周第一天
    calendar.add(Calendar.DATE, -dayInWeek + 1);//把日期往后增加一天.整数往后推,负数往前移动
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String str = sdf.format(calendar.getTime());
    return str;
}
项目:sstore-soft    文件:CETxnInputGenerator.java   
public TimestampType generateNonUniformTradeDTS( long maxTimeInMS, int aValue, int sValue ){
    GregorianCalendar tradeTime = new GregorianCalendar(TPCEConstants.initialTradePopulationBaseYear,
                                            TPCEConstants.initialTradePopulationBaseMonth,
                                            TPCEConstants.initialTradePopulationBaseDay,
                                            TPCEConstants.initialTradePopulationBaseHour,
                                            TPCEConstants.initialTradePopulationBaseMinute,
                                            TPCEConstants.initialTradePopulationBaseSecond );   
    long tradeTimeOffset;

    tradeTimeOffset = rnd.rndNU( 1, maxTimeInMS, aValue, sValue );
    return EGenDate.getTimeStamp(EGenDate.AddWorkMs( tradeTime.getTime(), tradeTimeOffset ));

}
项目:openjdk-jdk10    文件:HttpCookie.java   
private long expiryDate2DeltaSeconds(String dateString) {
    Calendar cal = new GregorianCalendar(GMT);
    for (int i = 0; i < COOKIE_DATE_FORMATS.length; i++) {
        SimpleDateFormat df = new SimpleDateFormat(COOKIE_DATE_FORMATS[i],
                                                   Locale.US);
        cal.set(1970, 0, 1, 0, 0, 0);
        df.setTimeZone(GMT);
        df.setLenient(false);
        df.set2DigitYearStart(cal.getTime());
        try {
            cal.setTime(df.parse(dateString));
            if (!COOKIE_DATE_FORMATS[i].contains("yyyy")) {
                // 2-digit years following the standard set
                // out it rfc 6265
                int year = cal.get(Calendar.YEAR);
                year %= 100;
                if (year < 70) {
                    year += 2000;
                } else {
                    year += 1900;
                }
                cal.set(Calendar.YEAR, year);
            }
            return (cal.getTimeInMillis() - whenCreated) / 1000;
        } catch (Exception e) {
            // Ignore, try the next date format
        }
    }
    return 0;
}
项目:logistimo-web-service    文件:AssetController.java   
@RequestMapping(value = "/temperature/{vendorId}/{deviceId}/{mpOrSensorId}", method = RequestMethod.GET)
public
@ResponseBody
DeviceTempsModel getTemperature(@PathVariable String vendorId, @PathVariable String deviceId,
                                @PathVariable String mpOrSensorId,
                                @RequestParam("size") Integer size,
                                @RequestParam("sint") Integer samplingInt,
                                @RequestParam(value = "edate", required = false) String endDate,
                                @RequestParam(value = "at", defaultValue = "1") Integer assetType,
                                HttpServletRequest request) {
  SecureUserDetails sUser = SecurityMgr.getUserDetails(request.getSession());
  String timezone = sUser.getTimezone();
  deviceId = AssetUtil.decodeURLParameters(deviceId);
  long end = LocalDateUtil.getCurrentTimeInSeconds(timezone);
  //long end = -1;

  if (endDate != null && !endDate.isEmpty()) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone(timezone));
    try {
      cal.setTime(sdf.parse(endDate));
      cal.add(Calendar.DATE, 1);
      LocalDateUtil.resetTimeFields(cal);
      end = cal.getTimeInMillis() / 1000;
    } catch (ParseException e) {
      xLogger.warn("Exception while parsing end date", e);
    }
  }

  return assetBuilder.buildAssetTemperatures(AssetUtil
          .getTemperatureResponse(vendorId, deviceId, mpOrSensorId, assetType, 1, end, 1, size),
      (endDate != null && !endDate.isEmpty()) ? end : 0, samplingInt, timezone);
}
项目:Musicoco    文件:AutoSwitchThemeController.java   
public void setAlarm() {

        // UPDATE: 2017/8/24 更新 时间段自定义
        current = Calendar.getInstance();
        nightThemeStart = new GregorianCalendar(
                current.get(Calendar.YEAR),
                current.get(Calendar.MONTH),
                current.get(Calendar.DAY_OF_MONTH),
                22, 30); // 22:30 切换到夜间模式

        nightThemeEnd = (Calendar) nightThemeStart.clone();
        nightThemeEnd.add(Calendar.DAY_OF_MONTH, 1); // 后一天
        nightThemeEnd.set(Calendar.HOUR_OF_DAY, 7); // 07:00 切换到白天模式
        nightThemeEnd.set(Calendar.MINUTE, 0);

        checkTheme();
        isSet = true;

        Intent intentS = new Intent();
        Intent intentE = new Intent();

        intentS.setAction(BroadcastManager.FILTER_APP_THEME_CHANGE_AUTOMATIC);
        intentS.putExtra(BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_TOKEN,
                BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_DARK);

        intentE.setAction(BroadcastManager.FILTER_APP_THEME_CHANGE_AUTOMATIC);
        intentE.putExtra(BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_TOKEN,
                BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_WHITE);

        piS = PendingIntent.getBroadcast(context, 0, intentS, 0);
        piE = PendingIntent.getBroadcast(context, 1, intentE, 0);

        alarmManager.set(AlarmManager.RTC_WAKEUP, nightThemeStart.getTimeInMillis(), piS);
        alarmManager.set(AlarmManager.RTC_WAKEUP, nightThemeEnd.getTimeInMillis(), piE);

    }
项目:parabuild-ci    文件:QuarterDateFormat.java   
/**
 * Creates a new instance for the specified time zone.
 * 
 * @param zone  the time zone (<code>null</code> not permitted).
 * @param quarterSymbols  the quarter symbols.
 */
public QuarterDateFormat(TimeZone zone, String[] quarterSymbols) {
    if (zone == null) {
        throw new IllegalArgumentException("Null 'zone' argument.");   
    }
    this.calendar = new GregorianCalendar(zone);
    this.quarters = quarterSymbols;

    // the following is never used, but it seems that DateFormat requires
    // it to be non-null.  It isn't well covered in the spec, refer to 
    // bug parade 5061189 for more info.
    this.numberFormat = NumberFormat.getNumberInstance();
}
项目:Embeddable-BSBM    文件:VirtSerializer.java   
private void convertProductFeature(ProductFeature pf) throws IOException
{
    StringBuffer values = getBuffer(tables.productFeatureInsertCounter++, "ProductFeature");
    values.append("(");

    //nr
    values.append(pf.getNr());
    values.append(",");

    //rdfs:label
    values.append("'");
    values.append(pf.getLabel());
    values.append("',");

    //rdfs:comment
    values.append("'");
    values.append(pf.getComment());
    values.append("',");

    //dc:publisher
    values.append(pf.getPublisher());
    values.append(",");

    //dc:date
    GregorianCalendar date = new GregorianCalendar();
    date.setTimeInMillis(pf.getPublishDate());
    String dateString = DateGenerator.formatDate(date);
    values.append("cast ('");
    values.append(dateString);
    values.append("' as date))");

    if(tables.productFeatureInsertCounter>=insertNumber) {
        tables.productFeatureInsertCounter = 0;
        values.append(";\n");
    }
    tables.productFeatureDump.append(values);
}
项目:applecommander    文件:LittleEndianByteInputStream.java   
/**
 * Read the TimeRec into a Java Date object.
 * Note that years 00-39 are assumed to be 2000-2039 per the NuFX addendum
 * at http://www.nulib.com/library/nufx-addendum.htm.
 * @see <a href="http://www.nulib.com/library/nufx-addendum.htm">NuFX addendum</a>
 */
public Date readDate() throws IOException {
    byte[] data = readBytes(TIMEREC_LENGTH);
    if (Arrays.equals(TIMEREC_NULL, data)) return null;
    int year = data[TIMEREC_YEAR]+1900;
    if (year < 1940) year+= 100;
    GregorianCalendar gc = new GregorianCalendar(year, data[TIMEREC_MONTH]-1, data[TIMEREC_DAY], 
            data[TIMEREC_HOUR], data[TIMEREC_MINUTE], data[TIMEREC_SECOND]);
    return gc.getTime();
}
项目:android-project-gallery    文件:DateUtils.java   
/**
 * 返回当前年的第一天
 * 
 * @return
 */
public static long getFirstDayOfYear()
{
    Calendar calendar = new GregorianCalendar();
    calendar.set(Calendar.DAY_OF_YEAR, 1);

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Log.D(TAG, "getFirstDayOfYear: " + calendar.getTime());
    return calendar.getTimeInMillis();
}
项目:ProyectoPacientes    文件:ServerPreparedStatement.java   
private Calendar getDefaultTzCalendar() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.defaultTzCalendar == null) {
            this.defaultTzCalendar = new GregorianCalendar(TimeZone.getDefault());
        }

        return this.defaultTzCalendar;
    }
}
项目:logistimo-web-service    文件:SMSUtil.java   
public static Date populateActualTransactionDate(Long domainId, String actualTD) {
  DomainConfig c = DomainConfig.getInstance(domainId);
  Calendar calendar = GregorianCalendar.getInstance();
  if (c != null && StringUtils.isNotEmpty(c.getTimezone())) {
    calendar.setTimeZone(TimeZone.getTimeZone(c.getTimezone()));
  }
  if (actualTD != null) {
    String[] date = actualTD.split("/");
    int day = Integer.parseInt(date[0]);
    int month = Integer.parseInt(date[1]) - 1;
    int year = Integer.parseInt(date[2]);
    calendar.set(year, month, day, 0, 0, 0);
  }
  return calendar.getTime();
}
项目:AngularAndSpring    文件:MongoUtils.java   
private static final Query buildQuery(Optional<String> pair, boolean ascending) {
    Calendar cal = GregorianCalendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR, -1);
    Query query = new Query();
    if (pair.isPresent()) {
        query.addCriteria(Criteria.where("pair").is(pair.get()));
    }
    query.addCriteria(Criteria.where("createdAt").gt(cal.getTime()));
    if (ascending) {
        query.with(Sort.by("createdAt").ascending());
    } else {
        query.with(Sort.by("createdAt").descending());
    }
    return query;
}