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


Java DateFormat.setTimeZone方法代码示例

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


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

示例1: convert

import java.text.DateFormat; //导入方法依赖的package包/类
@Override
public String convert(Player o) {
	InetAddress rawIp = o.getAddress().getAddress();
	String ip = rawIp.toString().replaceAll("/", "");
	JSONObject jsonParsed = null;
	try {
		jsonParsed = JsonReader.readJsonFromUrl("http://freegeoip.net/json/" + ip);
	} catch (JSONException | IOException e) {
		e.printStackTrace();
	}
	String jsonValue = (String) jsonParsed.get("time_zone");
	Date date = new Date();
	DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
	df.setTimeZone(TimeZone.getTimeZone(jsonValue));
	return df.format(date);
}
 
开发者ID:WheezyGold7931,项目名称:skLib,代码行数:17,代码来源:ExprFormatDateOfPlayer.java

示例2: test_for_objectKey

import java.text.DateFormat; //导入方法依赖的package包/类
public void test_for_objectKey() throws Exception {
    DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", JSON.defaultLocale);
    simpleDateFormat.setTimeZone(JSON.defaultTimeZone);
    Map<Integer, User> map = new HashMap<Integer, User>();

    User user = new User();
    user.setId(1);
    user.setIsBoy(true);
    user.setName("leno.lix");
    user.setBirthDay(simpleDateFormat.parse("2012-03-07 22:38:21"));
    user.setGmtCreate(new java.sql.Date(simpleDateFormat.parse("2012-02-03 22:38:21").getTime()));

    map.put(1, user);

    String mapJson = JSON.toJSONString(map, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue);

    System.out.println(mapJson);

    Object object = JSON.parse(mapJson);

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:Bug_for_lenolix_8.java

示例3: log

import java.text.DateFormat; //导入方法依赖的package包/类
private void log(LogMessage logMessage, LogLevel level, String loggerName) {
	String logMessageString;
	if (config.getLogInPlainString()) {
		StringBuilder sb = new StringBuilder();
		sb.append("[CID: ").append(logMessage.getCorrelationId());
		if (StringUtils.isNotBlank(logMessage.getCorrelationIdLocal())) {
			sb.append(" CID.Local: ").append(logMessage.getCorrelationIdLocal());
		}
		sb.append("] ").append(logMessage.getMessage());
		String varsInString = LogHelper.variablesToString(logMessage.getVariables(), config.getLogVariableType());
		if (varsInString.length() > 0) {
			sb.append(" [").append(varsInString).append("]");
		}
		if (logMessage.getThrowable() != null) {
			Throwable t = logMessage.getThrowable();
			sb.append("\nException: ").append(ExceptionUtils.getMessage(t)).append(" ")
					.append(ExceptionUtils.getStackTrace(logMessage.getThrowable()));
			sb.append("");
		}
		logMessageString = sb.toString();
	} else {
		TimeZone tz = TimeZone.getTimeZone("UTC");
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		df.setTimeZone(tz);
		logMessage.setTimestamp(df.format(new Date()));
		logMessage.setLevel(level.toString());
		logMessage.setLogger(loggerName);
		logMessage.setThread(Thread.currentThread().toString());
		Gson gson = new GsonBuilder().disableHtmlEscaping().disableHtmlEscaping().create();
		logMessageString = gson.toJson(logMessage);
	}

	Logger logger = LogManager.getLogger(loggerName);
	switch (level) {
	case INFO:
		logger.info(logMessageString);
		break;
	case ERROR:
		logger.error(logMessageString);
		break;
	case FATAL:
		logger.fatal(logMessageString);
		break;
	case DEBUG:
		logger.debug(logMessageString);
		break;
	}
}
 
开发者ID:iac-m,项目名称:mule-json-logger,代码行数:49,代码来源:JsonLogger.java

示例4: formatWithTimeZone

import java.text.DateFormat; //导入方法依赖的package包/类
protected String formatWithTimeZone(
        String template,
        Object[] arguments, 
        Locale locale,
        TimeZone timezone) 
{
    MessageFormat mf = new MessageFormat(" ");
    mf.setLocale(locale);
    mf.applyPattern(template);
    if (!timezone.equals(TimeZone.getDefault())) 
    {
        Format[] formats = mf.getFormats();
        for (int i = 0; i < formats.length; i++) 
        {
            if (formats[i] instanceof DateFormat) 
            {
                DateFormat temp = (DateFormat) formats[i];
                temp.setTimeZone(timezone);
                mf.setFormat(i,temp);
            }
        }
    }
    return mf.format(arguments);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:LocalizedMessage.java

示例5: determineBackupFile

import java.text.DateFormat; //导入方法依赖的package包/类
private File determineBackupFile() {
    Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.mkdirs();
    checkState(Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.isDirectory(), "%s is not a directory",
            Constants.Files.EXTERNAL_WALLET_BACKUP_DIR);

    final DateFormat dateFormat = Iso8601Format.newDateFormat();
    dateFormat.setTimeZone(TimeZone.getDefault());

    for (int i = 0; true; i++) {
        final StringBuilder filename = new StringBuilder(Constants.Files.EXTERNAL_WALLET_BACKUP);
        filename.append('-');
        filename.append(dateFormat.format(new Date()));
        if (i > 0)
            filename.append(" (").append(i).append(')');

        final File file = new File(Constants.Files.EXTERNAL_WALLET_BACKUP_DIR, filename.toString());
        if (!file.exists())
            return file;
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:21,代码来源:BackupWalletDialogFragment.java

示例6: getDate

import java.text.DateFormat; //导入方法依赖的package包/类
private String getDate(long timeStamp, String dateFormat)
{

    DateFormat objFormatter = new SimpleDateFormat(dateFormat);
    String timezone= Calendar.getInstance().getTimeZone().getDefault().getDisplayName();
    objFormatter.setTimeZone(TimeZone.getTimeZone(timezone));

    Calendar objCalendar =
            Calendar.getInstance(TimeZone.getTimeZone(timezone));
    objCalendar.setTimeInMillis(timeStamp*1000);
    String formatedDate= objFormatter.format(objCalendar.getTime());
    objCalendar.clear();
    return formatedDate;
}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:15,代码来源:DateFormater.java

示例7: fetchFromPool

import java.text.DateFormat; //导入方法依赖的package包/类
private DateFormat fetchFromPool() {
    final DateFormat format = pool.fetchFromPool();
    final TimeZone tz = timeZone != null ? timeZone : TimeZone.getDefault();
    if (!tz.equals(format.getTimeZone())) {
        format.setTimeZone(tz);
    }
    return format;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:ThreadSafeSimpleDateFormat.java

示例8: getFormat

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 获取指定时区的格式
 * 
 * @return
 */
public DateFormat getFormat(String format, int timeZone) {
	DateFormat sdf = new SimpleDateFormat(format);
	TimeZone zone = TimeZone.getTimeZone(timeZone < 0 ? "GMT" + timeZone : "GMT+" + timeZone);
	sdf.setTimeZone(zone);
	return sdf;
}
 
开发者ID:wooui,项目名称:springboot-training,代码行数:12,代码来源:DateUtil.java

示例9: formatDate

import java.text.DateFormat; //导入方法依赖的package包/类
private double formatDate(String dateString) {
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date startDate;

    try {
        startDate = formatter.parse(dateString);
    } catch (ParseException e) {
        throw new RuntimeException(this.getClass().getName() +
                ": could not parse time from argument \"" + dateString + "\"");
    }
    return new Time(startDate).getMJD();
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:14,代码来源:SwanTemplateDataObjectTest.java

示例10: getISO8601FormatDate

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 获取ISO8601格式化时间
 *
 * @return 格式化时间
 */
public static String getISO8601FormatDate() {
    TimeZone timeZone = TimeZone.getTimeZone("UTC");
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); //"Z" to indicate UTC
    dateFormat.setTimeZone(timeZone);
    return dateFormat.format(new Date());
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:12,代码来源:TimeUtils.java

示例11: retainServedDateFormat

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * For Last-Modified and Date headers, we should echo the date back in the exact format we were
 * served.
 */
@Test public void retainServedDateFormat() throws Exception {
  // Serve a response with a non-standard date format that OkHttp supports.
  Date lastModifiedDate = new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(-1));
  Date servedDate = new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(-2));
  DateFormat dateFormat = new SimpleDateFormat("EEE dd-MMM-yyyy HH:mm:ss z", Locale.US);
  dateFormat.setTimeZone(TimeZone.getTimeZone("EDT"));
  String lastModifiedString = dateFormat.format(lastModifiedDate);
  String servedString = dateFormat.format(servedDate);

  // This response should be conditionally cached.
  server.enqueue(new MockResponse()
      .addHeader("Last-Modified: " + lastModifiedString)
      .addHeader("Expires: " + servedString)
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));

  assertEquals("A", readAscii(openConnection(server.url("/").url())));
  assertEquals("A", readAscii(openConnection(server.url("/").url())));

  // The first request has no conditions.
  RecordedRequest request1 = server.takeRequest();
  assertNull(request1.getHeader("If-Modified-Since"));

  // The 2nd request uses the server's date format.
  RecordedRequest request2 = server.takeRequest();
  assertEquals(lastModifiedString, request2.getHeader("If-Modified-Since"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:ResponseCacheTest.java

示例12: _logCommError

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 通讯错误日志
 */
private static void _logCommError(Exception e, HttpURLConnection conn, String url,
                                  String appKey, String method, Map<String, String> params) {
    DateFormat df = new SimpleDateFormat(AlipayConstants.DATE_TIME_FORMAT);
    df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE));
    String sdkName = AlipayConstants.SDK_VERSION;
    String urlStr = null;
    String rspCode = "";
    if (conn != null) {
        try {
            urlStr = conn.getURL().toString();
            rspCode = "HTTP_ERROR_" + conn.getResponseCode();
        } catch (IOException ioe) {
        }
    } else {
        urlStr = url;
        rspCode = "";
    }
    StringBuilder sb = new StringBuilder();
    sb.append(df.format(new Date()));// 时间
    sb.append("^_^");
    sb.append(method);// API
    sb.append("^_^");
    sb.append(appKey);// APP
    sb.append("^_^");
    sb.append(getIp());// IP地址
    sb.append("^_^");
    sb.append(osName);// 操作系统
    sb.append("^_^");
    sb.append(sdkName);// SDK名字,这是例子,请换成其他名字
    sb.append("^_^");
    sb.append(urlStr);// 请求URL
    sb.append("^_^");
    sb.append(rspCode);
    sb.append("^_^");
    sb.append((e.getMessage() + "").replaceAll("\r\n", " "));
    clog.error(sb.toString());
}
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:41,代码来源:AlipayLogger.java

示例13: retainServedDateFormat

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * For Last-Modified and Date headers, we should echo the date back in the exact format we were
 * served.
 */
@Test public void retainServedDateFormat() throws Exception {
  // Serve a response with a non-standard date format that OkHttp supports.
  Date lastModifiedDate = new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(-1));
  Date servedDate = new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(-2));
  DateFormat dateFormat = new SimpleDateFormat("EEE dd-MMM-yyyy HH:mm:ss z", Locale.US);
  dateFormat.setTimeZone(TimeZone.getTimeZone("EDT"));
  String lastModifiedString = dateFormat.format(lastModifiedDate);
  String servedString = dateFormat.format(servedDate);

  // This response should be conditionally cached.
  server.enqueue(new MockResponse()
      .addHeader("Last-Modified: " + lastModifiedString)
      .addHeader("Expires: " + servedString)
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));

  assertEquals("A", readAscii(urlFactory.open(server.url("/").url())));
  assertEquals("A", readAscii(urlFactory.open(server.url("/").url())));

  // The first request has no conditions.
  RecordedRequest request1 = server.takeRequest();
  assertNull(request1.getHeader("If-Modified-Since"));

  // The 2nd request uses the server's date format.
  RecordedRequest request2 = server.takeRequest();
  assertEquals(lastModifiedString, request2.getHeader("If-Modified-Since"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:UrlConnectionCacheTest.java

示例14: logErrorScene

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 发生特别错误时记录完整错误现场
 */
public static void logErrorScene(Map<String, Object> rt, AlipayResponse tRsp,
                                 String appSecret) {
    if (!needEnableLogger) {
        return;
    }
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE));
    StringBuilder sb = new StringBuilder();
    sb.append("ErrorScene");
    sb.append("^_^");
    sb.append(tRsp.getErrorCode());
    sb.append("^_^");
    sb.append(tRsp.getSubCode());
    sb.append("^_^");
    sb.append(ip);
    sb.append("^_^");
    sb.append(osName);
    sb.append("^_^");
    sb.append(df.format(new Date()));
    sb.append("^_^");
    sb.append("ProtocalMustParams:");
    appendLog((AlipayHashMap) rt.get("protocalMustParams"), sb);
    sb.append("^_^");
    sb.append("ProtocalOptParams:");
    appendLog((AlipayHashMap) rt.get("protocalOptParams"), sb);
    sb.append("^_^");
    sb.append("ApplicationParams:");
    appendLog((AlipayHashMap) rt.get("textParams"), sb);
    sb.append("^_^");
    sb.append("Body:");
    sb.append((String) rt.get("rsp"));
    blog.error(sb.toString());
}
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:37,代码来源:AlipayLogger.java

示例15: convertDateToString

import java.text.DateFormat; //导入方法依赖的package包/类
public static String convertDateToString(Date date, String pattern) {
	DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat(
		pattern);

	if (Validator.isNull(date) || Validator.isNull(pattern)) {
		return StringPool.BLANK;
	}

	dateFormat.setTimeZone(TimeZoneUtil.getTimeZone("Asia/Ho_Chi_Minh"));

	Calendar calendar = Calendar.getInstance();

	calendar.setTime(date);

	return dateFormat.format(calendar.getTime());
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:17,代码来源:APIDateTimeUtils.java


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