当前位置: 首页>>代码示例>>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;未经允许,请勿转载。