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


Java SimpleDateFormat.setTimeZone方法代碼示例

本文整理匯總了Java中java.text.SimpleDateFormat.setTimeZone方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleDateFormat.setTimeZone方法的具體用法?Java SimpleDateFormat.setTimeZone怎麽用?Java SimpleDateFormat.setTimeZone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.SimpleDateFormat的用法示例。


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

示例1: updateSensor

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
@Override
public void updateSensor(JsonObject obj) throws UpdateException {
    try {
        setName(obj.getString("name"));
        JsonObject state = obj.getJsonObject("state");

        Boolean pres = state.getBoolean("presence");

        SimpleDateFormat sdf = new SimpleDateFormat(Constants.HUEDATEFORMAT);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        Date time = sdf.parse(state.getString("lastupdated"));
        SensorValue<Boolean> val = new SensorValue<>(time, pres);
        updateValue(val);

        JsonObject conf = obj.getJsonObject("config");
        setOn(conf.getBoolean("on"));
        setBattery(conf.getInt("battery"));
        setReachable(conf.getBoolean("reachable"));

    } catch (ParseException | NullPointerException | ClassCastException ex) {
        throw new UpdateException("Error updating temp sensor", ex);
    }
}
 
開發者ID:dainesch,項目名稱:HueSense,代碼行數:24,代碼來源:PresenceSensor.java

示例2: computeCheckPeriod

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
int computeCheckPeriod() {
    OpenraspRollingCalendar rollingCalendar = new OpenraspRollingCalendar(gmtTimeZone, Locale.getDefault());
    // set sate to 1970-01-01 00:00:00 GMT
    Date epoch = new Date(0);
    if(datePattern != null) {
        for(int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
            simpleDateFormat.setTimeZone(gmtTimeZone); // do all date formatting in GMT
            String r0 = simpleDateFormat.format(epoch);
            rollingCalendar.setType(i);
            Date next = new Date(rollingCalendar.getNextCheckMillis(epoch));
            String r1 =  simpleDateFormat.format(next);
            //System.out.println("Type = "+i+", r0 = "+r0+", r1 = "+r1);
            if(r0 != null && r1 != null && !r0.equals(r1)) {
                return i;
            }
        }
    }
    return TOP_OF_TROUBLE; // Deliberately head for trouble...
}
 
開發者ID:baidu,項目名稱:openrasp,代碼行數:21,代碼來源:OpenraspDailyRollingFileAppender.java

示例3: test_codec

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
public void test_codec() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("{\"value\":\"2016-04-29\"}"));
    reader.setLocale(Locale.CHINA);
    reader.setTimzeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    
    Model model = reader.readObject(Model.class);
    Assert.assertNotNull(model.value);
    
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
    format.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    Date date = format.parse("2016-04-29");
    Assert.assertEquals(date.getTime(), model.value.getTime());
    
    Assert.assertEquals(TimeZone.getTimeZone("Asia/Shanghai"), reader.getTimzeZone());
    Assert.assertEquals(Locale.CHINA, reader.getLocal());
    
    reader.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:DateTest_tz.java

示例4: getDateLabel

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
public String getDateLabel(Weather weather, int i) {
    if ((i + 4) % 4 == 0) {
        SimpleDateFormat resultFormat = new SimpleDateFormat("E");
        resultFormat.setTimeZone(TimeZone.getDefault());
        String output = resultFormat.format(weather.getDate());
        if (!output.equals(previous)) {
            previous = output;
            return output;
        } else {
            return "";
        }
    } else {
        return "";
    }
}
 
開發者ID:hichemcesar24,項目名稱:Weather-Android,代碼行數:16,代碼來源:GraphActivity.java

示例5: getDateFromJson

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
/**
 * Parse a json node in order to create a Date object
 *
 * @param jsonNode json to parse to Date
 * @return null if a ParseException has been thrown, else the Date object created
 * @throws NullPointerException if jsonNode is null
 */
static Date getDateFromJson(JsonNode jsonNode) {
    Objects.requireNonNull(jsonNode);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss-SSS");
    TimeZone tz = TimeZone.getTimeZone("CET");
    String timeString = jsonNode.toString();
    timeString = timeString.substring(1, timeString.length() - 4);
    dateFormat.setTimeZone(tz);
    try {
        return dateFormat.parse(timeString);
    } catch (ParseException err) {
        LOGGER.error(err.getMessage());
        return null;
    }
}
 
開發者ID:IKB4Stream,項目名稱:IKB4Stream,代碼行數:22,代碼來源:FacebookMock.java

示例6: simpleParse

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
private Date simpleParse(String dateString, String dateFormat) throws ParseException {
    SimpleDateFormat format = new SimpleDateFormat(dateFormat);
    format.setTimeZone(TimeZone.getTimeZone("GMT"));
    format.setLenient(false);
    Date parsed = format.parse(dateString);
    return parsed;
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:8,代碼來源:DateParserTest.java

示例7: getSignKey

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
private byte[] getSignKey(String secretKey, Date date) {
    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
    sf.setTimeZone(TimeZone.getTimeZone("GMT+0"));

    byte[] k1 = this.sign(secretKey.getBytes(), sf.format(date));
    byte[] k2 = this.sign(k1, this.hostname);

    return k2;
}
 
開發者ID:lablup,項目名稱:backend.ai-client-java,代碼行數:10,代碼來源:Auth.java

示例8: putTime

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
/**
 * Private helper routine for marshalling a DER UTC/Generalized
 * time/date value. If the tag specified is not that for UTC Time
 * then it defaults to Generalized Time.
 * @param d the date to be marshalled
 * @param tag the tag for UTC Time or Generalized Time
 */
private void putTime(Date d, byte tag) throws IOException {

    /*
     * Format the date.
     */

    TimeZone tz = TimeZone.getTimeZone("GMT");
    String pattern = null;

    if (tag == DerValue.tag_UtcTime) {
        pattern = "yyMMddHHmmss'Z'";
    } else {
        tag = DerValue.tag_GeneralizedTime;
        pattern = "yyyyMMddHHmmss'Z'";
    }

    SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
    sdf.setTimeZone(tz);
    byte[] time = (sdf.format(d)).getBytes("ISO-8859-1");

    /*
     * Write the formatted date.
     */

    write(tag);
    putLength(time.length);
    write(time);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:DerOutputStream.java

示例9: toGMTString

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
private static String toGMTString(Date date) {
    SimpleDateFormat sdf = new SimpleDateFormat(
            "EEE, dd MMM y HH:mm:ss 'GMT'", Locale.US);
    TimeZone gmtZone = TimeZone.getTimeZone("GMT");
    sdf.setTimeZone(gmtZone);
    GregorianCalendar gc = new GregorianCalendar(gmtZone);
    gc.setTimeInMillis(date.getTime());
    return sdf.format(date);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:HttpRequest.java

示例10: checkParseCompressedIso8601Date

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
private static boolean checkParseCompressedIso8601Date() throws ParseException {
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
    sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
    String formatted = sdf.format(date);
    Date expected = sdf.parse(formatted);
    Date actual = new Date(DateUtils.compressedIso8601DateFormat.parseMillis(formatted));
    return expected.equals(actual);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:10,代碼來源:JodaTime.java

示例11: parse

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
public static Date parse(String format, String dateText) throws ParseException {
	SimpleDateFormat sdf = new SimpleDateFormat(format);
	TimeZone timeZone = getDefaultTimeZone();
	if (timeZone != null) {
		sdf.setTimeZone(timeZone);
	}
	return sdf.parse(dateText);
}
 
開發者ID:VonChange,項目名稱:headb,代碼行數:9,代碼來源:HDateUtils.java

示例12: initialValue

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
@Override
protected SimpleDateFormat initialValue()
{
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return format;
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:8,代碼來源:WebDavUtil.java

示例13: doSetTrackInfo

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
@SuppressLint("SimpleDateFormat")
private void doSetTrackInfo() {
    if (getPlayer() == null)
        return;
    TextView current = (TextView) findViewById(R.id.musicActivityCurrentItem);
    current.setText(getPlayer().getCurrentItemTitle());
    TextView position = (TextView) findViewById(R.id.musicActivityPosition);
    position.setText(getPlayer().getPositionString());
    TextView next = (TextView) findViewById(R.id.musicActivityNextItem);
    next.setText(getPlayer().getNextItemTitle());
    ImageView albumArtView = (ImageView) findViewById(R.id.musicActivityImageView);
    URI albumArtUri = getPlayer().getAlbumArt();
    if (null != albumArtUri) {
        ImageDownloadTask imageDownloadTask = new ImageDownloadTask(albumArtView);
        imageDownloadTask.execute(Uri.parse(albumArtUri.toString()));
    }
    TextView duration = (TextView) findViewById(R.id.musicActivityDuration);
    duration.setText(getPlayer().getDuration());
    TextView elapsedTime = (TextView) findViewById(R.id.musicActivityElapsedTime);
    String elapsedTimeString = getPlayer().getElapsedTime();
    elapsedTime.setText(elapsedTimeString);
    String durationString = getPlayer().getDuration();
    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    try {
        Long elapsedTimeMillis = dateFormat.parse(elapsedTimeString).getTime();
        Long durationTimeMillis = dateFormat.parse(durationString).getTime();
        int progress;
        progress = Double.valueOf((elapsedTimeMillis.doubleValue()/  durationTimeMillis.doubleValue()) *100).intValue();
        if(seekBar != null) {
            seekBar.setProgress(progress);
        }
    }catch(ParseException pex){
        Log.d(getClass().getName(),"Error while parsing time string" , pex);
    }


}
 
開發者ID:theopenbit,項目名稱:yaacc-code,代碼行數:39,代碼來源:MusicPlayerActivity.java

示例14: DERUTCTime

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
/**
 * base constructer from a java.util.date object
 */
public DERUTCTime(
    Date time)
{
    SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmss'Z'");

    dateF.setTimeZone(new SimpleTimeZone(0,"Z"));

    this.time = Strings.toByteArray(dateF.format(time));
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:13,代碼來源:DERUTCTime.java

示例15: Generator

import java.text.SimpleDateFormat; //導入方法依賴的package包/類
/**
 * Constructor.
 */
Generator(ServletWriter out, Compiler compiler) throws JasperException {
    this.out = out;
    methodsBuffered = new ArrayList<GenBuffer>();
    charArrayBuffer = null;
    err = compiler.getErrorDispatcher();
    ctxt = compiler.getCompilationContext();
    fragmentHelperClass = new FragmentHelperClass("Helper");
    pageInfo = compiler.getPageInfo();

    ELInterpreter elInterpreter = null;
    try {
        elInterpreter = ELInterpreterFactory.getELInterpreter(
                compiler.getCompilationContext().getServletContext());
    } catch (Exception e) {
        err.jspError("jsp.error.el_interpreter_class.instantiation",
                e.getMessage());
    }
    this.elInterpreter = elInterpreter;

    /*
     * Temporary hack. If a JSP page uses the "extends" attribute of the
     * page directive, the _jspInit() method of the generated servlet class
     * will not be called (it is only called for those generated servlets
     * that extend HttpJspBase, the default), causing the tag handler pools
     * not to be initialized and resulting in a NPE. The JSP spec needs to
     * clarify whether containers can override init() and destroy(). For
     * now, we just disable tag pooling for pages that use "extends".
     */
    if (pageInfo.getExtends(false) == null || POOL_TAGS_WITH_EXTENDS) {
        isPoolingEnabled = ctxt.getOptions().isPoolingEnabled();
    } else {
        isPoolingEnabled = false;
    }
    beanInfo = pageInfo.getBeanRepository();
    varInfoNames = pageInfo.getVarInfoNames();
    breakAtLF = ctxt.getOptions().getMappedFile();
    if (isPoolingEnabled) {
        tagHandlerPoolNames = new Vector<String>();
    } else {
        tagHandlerPoolNames = null;
    }
    timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:48,代碼來源:Generator.java


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