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


Java TimeZone類代碼示例

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


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

示例1: ApiMedicion

import java.util.TimeZone; //導入依賴的package包/類
public ApiMedicion(Date measuredAt, String currentState, String avisoState, String avisoMaxToday, String escenarioToday, String escenarioTomorrow, String escenarioTomorrowManual, boolean isPureMadrid) {
    this.isPureMadrid = isPureMadrid;
    MIN_VALUE_PREAVISO = isPureMadrid ? 180 : 140; //180;
    MIN_VALUE_AVISO = isPureMadrid ? 200 : 180; //200;
    MIN_VALUE_ALERTA = isPureMadrid ? 400 : 300; //400;

    this.aviso = currentState;
    this.avisoState = avisoState;
    this.avisoMaxToday = avisoMaxToday;
    this.escenarioStateToday = escenarioToday;
    this.escenarioStateTomorrow = escenarioTomorrow;
    this.escenarioManualTomorrow = escenarioTomorrowManual;

    if (measuredAt == null){
        this.measuredAt = null;
    } else {
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
        calendar.setTime(measuredAt);
        this.measuredAt = calendar;
    }
}
 
開發者ID:medialab-prado,項目名稱:puremadrid,代碼行數:22,代碼來源:ApiMedicion.java

示例2: onCreate

import java.util.TimeZone; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    Application application = (Application) getApplication();
    mDatabase = application.getDatabase();

    if (savedInstanceState != null)
        mListId = savedInstanceState.getString(INTENT_LIST_ID);
    else
        mListId = getIntent().getStringExtra(INTENT_LIST_ID);

    Query query = getQuery();
    mAdapter = new TaskAdapter(this, query.toLiveQuery());

    ListView listView = (ListView) findViewById(R.id.list);
    listView.setAdapter(mAdapter);
    setListHeader(listView);
    setListItemLongClick(listView);

    mDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
 
開發者ID:Kaufland,項目名稱:andcouchbaseentity,代碼行數:25,代碼來源:TaskActivity.java

示例3: testHourOfDay

import java.util.TimeZone; //導入依賴的package包/類
@Test
public void testHourOfDay() {
    TimeZone gmt = TimeZone.getTimeZone("Universal");
    Calendar test = Calendar.getInstance(gmt);
    test.set(Calendar.YEAR, 1969);
    test.set(Calendar.MONTH, Calendar.JULY);
    test.set(Calendar.DATE, 20);
    test.set(Calendar.HOUR_OF_DAY, 3);

    assertEquals(1969, test.get(Calendar.YEAR));
    assertEquals(Calendar.JULY, test.get(Calendar.MONTH));
    assertEquals(20, test.get(Calendar.DATE));
    assertEquals(3, test.get(Calendar.HOUR));
    assertEquals(Calendar.AM, test.get(Calendar.AM_PM));
    assertEquals(3, test.get(Calendar.HOUR_OF_DAY));
}
 
開發者ID:neuhalje,項目名稱:TimeAndMoney,代碼行數:17,代碼來源:JavaUtilCalendarQuirksTest.java

示例4: testLoad

import java.util.TimeZone; //導入依賴的package包/類
@Test
public void testLoad() throws Exception {
    new ExecuteAsTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC))
            .run(() -> assertThat(
                    load("2017-08-28T07:09:36.000000042Z")
                            .isEqual(OffsetDateTime.of(2017, 8, 28, 7, 9, 36, 42, ZoneOffset.UTC)),
                    is(true)
            ));
}
 
開發者ID:n15g,項目名稱:spring-boot-gae,代碼行數:10,代碼來源:OffsetDateTimeStringTranslatorFactoryTest.java

示例5: withTimeZone

import java.util.TimeZone; //導入依賴的package包/類
/**
 * Returns a version of this formatter customized to the provided time zone.
 */
public DateFormatter withTimeZone(TimeZone tz) {
  if (!tz.equals(timeZone)) {
    return new YMDDateFormatter(requestedFields, localeName, tz);
  }
  return this;
}
 
開發者ID:abhijitvalluri,項目名稱:fitnotifications,代碼行數:10,代碼來源:YMDDateFormatter.java

示例6: getDateTimeFromString

import java.util.TimeZone; //導入依賴的package包/類
public static long getDateTimeFromString(String strDate) {
    long nTimeNow = 0;

    if (strDate == null) {
        return 0;
    }

    try {
        SimpleDateFormat myFmt2 = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        myFmt2.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date dt = myFmt2.parse(strDate.trim());

        nTimeNow = dt.getTime();
    } catch (Exception ex) {
    }

    return nTimeNow;
}
 
開發者ID:StickyTolt,項目名稱:ForeverLibrary,代碼行數:20,代碼來源:MiscUtil.java

示例7: getBeijingNowTime

import java.util.TimeZone; //導入依賴的package包/類
public static String getBeijingNowTime(String format) {
    TimeZone timezone = TimeZone.getTimeZone("Asia/Shanghai");

    Date date = new Date(currentTimeMillis());
    SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
    formatter.setTimeZone(timezone);

    return formatter.format(date);
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:10,代碼來源:TimeUtil.java

示例8: getParser

import java.util.TimeZone; //導入依賴的package包/類
public CompositeFileEntryParser getParser(final String system, final TimeZone zone) {
    if(log.isDebugEnabled()) {
        log.debug(String.format("Select parser for system %s in zone %s", system, zone));
    }
    final CompositeFileEntryParser parser;
    if(null == zone) {
        parser = new FTPParserFactory().createFileEntryParser(system,
                TimeZone.getTimeZone(PreferencesFactory.get().getProperty("ftp.timezone.default")));
    }
    else {
        parser = new FTPParserFactory().createFileEntryParser(system, zone);
    }
    // Configure timezone
    parser.configure(null);
    return parser;
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:17,代碼來源:FTPParserSelector.java

示例9: setTimestampInternal

import java.util.TimeZone; //導入依賴的package包/類
private void setTimestampInternal(int parameterIndex, java.sql.Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward) throws SQLException {
    if (x == null) {
        setNull(parameterIndex, java.sql.Types.TIMESTAMP);
    } else {
        BindValue binding = getBinding(parameterIndex, false);
        resetToType(binding, MysqlDefs.FIELD_TYPE_DATETIME);

        if (!this.sendFractionalSeconds) {
            x = TimeUtil.truncateFractionalSeconds(x);
        }

        if (!this.useLegacyDatetimeCode) {
            binding.value = x;
        } else {
            Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar()
                    : getCalendarInstanceForSessionOrNew();

            binding.value = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(),
                    rollForward);
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:23,代碼來源:ServerPreparedStatement.java

示例10: getTimeZoneDisplay

import java.util.TimeZone; //導入依賴的package包/類
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = (String) cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:FastDateFormat.java

示例11: sign

import java.util.TimeZone; //導入依賴的package包/類
/**
 * Query string authentication. Query string authentication is useful for giving HTTP or
 * browser access to resources that would normally require authentication. The signature in the query
 * string secures the request.
 *
 * @param seconds Expire in n seconds from now in default timezone
 * @return A signed URL with a limited validity over time.
 */
protected DescriptiveUrl sign(final Path file, final int seconds) {
    // Determine expiry time for URL
    final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    expiry.add(Calendar.SECOND, seconds);
    final String secret = store.findLoginPassword(session.getHost());
    if(StringUtils.isBlank(secret)) {
        log.warn("No secret found in keychain required to sign temporary URL");
        return DescriptiveUrl.EMPTY;
    }
    String region = null;
    if(session.isConnected()) {
        region = session.getClient().getRegionEndpointCache()
                .getRegionForBucketName(containerService.getContainer(file).getName());
    }
    return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create(
            session.getHost(),
            session.getHost().getCredentials().getUsername(), secret,
            containerService.getContainer(file).getName(), region, containerService.getKey(file),
            expiry.getTimeInMillis())), DescriptiveUrl.Type.signed,
            MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3"))
                    + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")",
                    UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis()))
    );
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:33,代碼來源:S3UrlProvider.java

示例12: parseDate

import java.util.TimeZone; //導入依賴的package包/類
public static Date parseDate(String timestampStr, List<String> dateFormats, String timezone)
    throws ParseException {
  Date date = null;
  SimpleDateFormat sdf = new SimpleDateFormat();
  for (String s : dateFormats) {
    sdf.applyPattern(s);
    if (timezone != null && !timezone.isEmpty()) {
      sdf.setTimeZone(TimeZone.getTimeZone(timezone));
    }
    try {
      date = sdf.parse(timestampStr);
    } catch (ParseException ignored) {
      //do nothing
    }
  }
  if (date == null) {
    throw new ParseException(timestampStr, 0);
  }
  return date;
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:21,代碼來源:LocalDateUtil.java

示例13: getStartAndEndDateForWeek

import java.util.TimeZone; //導入依賴的package包/類
protected static Map<String, Object> getStartAndEndDateForWeek(String period) {
  Map<String, Object> dateMap = new HashMap<>();
  Map<String, Integer> periodMap = getDaysByPeriodStr(period);
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
  int firstDayOfWeek = calendar.getFirstDayOfWeek();        
  calendar.add(Calendar.DATE, -(calendar.get(Calendar.DAY_OF_WEEK)-firstDayOfWeek));
  calendar.add(Calendar.WEEK_OF_YEAR, 1);
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  String endDateStr = sdf.format(calendar.getTime());
  dateMap.put(endDate, endDateStr);
  dateMap.put(endTimeMilis, calendar.getTimeInMillis());
  calendar.add(periodMap.get(KEY), -(periodMap.get(VALUE)));
  calendar.add(Calendar.DATE, 1);
  calendar.set(Calendar.HOUR_OF_DAY,0);
  calendar.set(Calendar.MINUTE, 0);
  calendar.set(Calendar.SECOND, 0);
  calendar.set(Calendar.MILLISECOND, 0);
  dateMap.put(INTERVAL, "1w");
  dateMap.put(FORMAT, "yyyy-ww");
  String startDateStr = sdf.format(calendar.getTime());
  dateMap.put(startDate, startDateStr);
  dateMap.put(startTimeMilis, calendar.getTimeInMillis());
  return dateMap;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-lms-mw,代碼行數:26,代碼來源:BaseMetricsActor.java

示例14: getCredentialString

import java.util.TimeZone; //導入依賴的package包/類
@Test
public void getCredentialString() {
    ClientConfig config = new ClientConfig.Builder().accessKey("TESTESTSERSERESTSET").secretKey("KJSAKDFJASKFDJASDFJSAFDJSJFSAJFSDF").build();

    Auth auth = new Auth(config);
    String body = "";

    SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    ISO8601DATEFORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    String date_s = "2017-10-28T19:57:56";
    Date date = new Date();
    try {
        date = ISO8601DATEFORMAT.parse(date_s);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    String a = auth.getCredentialString("POST", "/v2/kernel/create", date, body);
    assertEquals(a, "TESTESTSERSERESTSET:dcd926f4b281e05d384b3debccd540b1cd9ad30c184f5797057616f3b86b2cc3");

}
 
開發者ID:lablup,項目名稱:backend.ai-client-java,代碼行數:22,代碼來源:AuthTest.java

示例15: toLocal

import java.util.TimeZone; //導入依賴的package包/類
public static String toLocal(String utc) {
    String pattern = "yyyyMMddHHmmss";
    try {
        SimpleDateFormat formater = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
        formater.setTimeZone(TimeZone.getTimeZone("GMT"));
        Date date = formater.parse(utc);
        formater.setTimeZone(TimeZone.getDefault());
        return formater.format(date);
    } catch (Exception e) {
        LOG.i(TAG, "[utc:" + utc + "] UTC to local failed(Exception)", e);
        return "";
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:14,代碼來源:TimeUtils.java


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