本文整理汇总了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);
}
}
示例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...
}
示例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();
}
示例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 "";
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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));
}
示例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"));
}