See in this image the schedule meeting is highlighted now this is for India timezone now if i open the same calendar in USA timezone the schedule should get changed according to there time zone so the calendar view should also be changed.我需要根据时区更改日历视图,例如,如果我在印度,我计划在下午3-4点开会,因此,当我们在印度时,日历将显示,但如果我在美国或巴黎,我从下午3-4点安排的会议将在他们的日历视图中以不同方式显示。
目前我有以下代码
final Date date = new Date();
final DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
formatter.setTimeZone(TimeZone.getTimeZone(timezone));
currentstartDate = formatter.format(date);
currentendDate = formatter.format(date);我正在从其他bean获取时区,它在调试时被检查过
发布于 2016-03-01 17:43:18
你试过使用SimpleDateFormat吗?
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));完整的代码在这里:包一般;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class DateTimeTZ {
public static void main(String[] args) throws ParseException {
SimpleDateFormat isoFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
Date date1 = isoFormat.parse("03/01/2016 09:01 AM");
isoFormat.setTimeZone(TimeZone.getTimeZone("Asia/Mumbai"));
isoFormat.applyPattern("dd MMM yyyy HH:mm:ss z");
System.out.println("Current Date and Time in IST time zone: " + isoFormat.format(date1));
isoFormat.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
isoFormat.applyPattern("dd MMM yyyy HH:mm:ss z");
System.out.println("Current Date and Time in SGT time zone: " + isoFormat.format(date1));
isoFormat.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
isoFormat.applyPattern("dd MMM yyyy HH:mm:ss z");
System.out.println("Current Date and Time in JST time zone: " + isoFormat.format(date1));
}
}输出:
IST时区的当前日期和时间: 01 Mar 2016 03:31:00 GMT
SGT时区的当前日期和时间: 01 Mar 2016 11:31:00 SGT
JST时区当前日期和时间: 2016年3月1日12:31:00 JST
https://stackoverflow.com/questions/35719200
复制相似问题