[英]convert date and time into selected timezone
i have a list of time zones of diffrent countries in a selectbox and have a textbox where user can enter date and time in a specified format only which is yyyy-MM-dd hh:mm:ss
. 我在选择框中有一个不同国家的时区列表,并有一个文本框,用户只能以
yyyy-MM-dd hh:mm:ss
的指定格式输入日期和时间。
i want entered timezone to be converted in to selcted timezone from list. 我想将输入的时区从列表转换为选择的时区。 How can i do this.
我怎样才能做到这一点。
<option value="Pacific/Apia">( GMT -11:0 ) West Samoa Time ( Pacific/Apia )</option>
<option value="Pacific/Midway">( GMT -11:0 ) Samoa Standard Time ( Pacific/Midway )</option>
<option value="Pacific/Niue">( GMT -11:0 ) Niue Time ( Pacific/Niue )</option>
<option value="Pacific/Pago_Pago">( GMT -11:0 ) Samoa Standard Time ( Pacific/Pago_Pago )</option>
<option value="Pacific/Samoa">( GMT -11:0 ) Samoa Standard Time ( Pacific/Samoa )</option>
<option value="US/Samoa">( GMT -11:0 ) Samoa Standard Time ( US/Samoa )</option>
Textbox 文本框
<input type="text" name="createdOnGMTDate" id="createdOnGMTDate" style="width:200px;"/>
Thanks 谢谢
You can use SimpleDateFormat to format date with a certain pattern with a predefined locale. 您可以使用SimpleDateFormat使用具有预定义语言环境的特定模式来格式化日期。 For example:
例如:
Calendar cal = Calendar.getInstance(locale);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT-11"));
String now = sdf.format(cal.getTime());
Try below code, may be this will help you. 尝试以下代码,可能会对您有所帮助。
DateFormat formatter= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss Z");
formatter.setTimeZone(TimeZone.getTimeZone("Europe/London"));
System.out.println(formatter.format(date));
formatter.setTimeZone(TimeZone.getTimeZone("Europe/Athens"));
System.out.println(formatter.format(instance2.getTime()))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.