首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据时区更改日历视图

根据时区更改日历视图
EN

Stack Overflow用户
提问于 2016-03-01 17:34:57
回答 1查看 57关注 0票数 0

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点安排的会议将在他们的日历视图中以不同方式显示。

目前我有以下代码

代码语言:javascript
复制
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获取时区,它在调试时被检查过

EN

回答 1

Stack Overflow用户

发布于 2016-03-01 17:43:18

你试过使用SimpleDateFormat吗?

代码语言:javascript
复制
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

完整的代码在这里:包一般;

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35719200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档