java 获取客户端时区,在服务器端java类中读取客户端时区

I have a client side program that sends a time to the server side program.

I am using Callendar object to pass the time values from client to server.

My client program is located at the Sri Lanka and the server is located at the UK.

When I am sending the time(Ex : 2011-11-21T12:43:41.352+05:30) in client side, as usually the time converting to UK Time at the server (Ex : 2011-11-21T07:13:411.352+00:00).

What I want to do is I want to get the time that I am sending in the client program with the Time Zone in the client program.(In simple terms, I want to read the time in server without TimeZone conversions applying to the time that is sent by the client side program. So in the server I want to get the time as 2011-11-21T12:43:41.352+05:30 not as 2011-11-21T07:13:411.352+00:00).

Can I know is this possible with java to do and if yes how?

Client Side :

Calendar cal1 = Calendar.getInstance();

Date indate = new Date(); // this shows as 2011-11-21T12:43:41.352+05:30

searchDateRange_type0.setStart(cal1);

cal1.setTime(inDate);

Serever Side :

SearchDateRange_type0 serachDaterange= criterion_type.getSearchDateRange();

checkInDate = serachDaterange.getStart().getTime(); //I read this as 2011-11-21T07:13:411.352+00:00

解决方案

The issue here is that when java client Calendar converting Date its setting up its time zone too. if you will to clear this off and only need to get the date from the server Calendar object , set the client Calendar time minute and seconds to 0 when you set up the time zone in client.

ex. in client side ,

Date indate = new Date("21-Nov-2011");

Calendar cal1 = Calendar.getInstance();

cal1.setTime(indate);

// set the time zone same as server time zone.

cal1.setTimeZone(TimeZone.getTimeZone("GMT"));

// then clear out the rest in oder to get only the date.

cal1.set(Calendar.HOUR, 0);

cal1.set(Calendar.MINUTE, 0);

cal1.set(Calendar.SECOND, 0);

so the server only get the same date passed from the client with out time zone or the hours.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值