1

I'm writing this application which needs to handle DST in android. I've written a small test code that would do the following. In addition I'm not using network provided date time in this case.

If i run the application and display the current time and go to android settings and change the time zone without exiting the application and then get the current Time from the application it wouldn't give me the new time change.

UPDATE Following is the code

btnStart.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Date dt = new Date(System.currentTimeMillis());
                txtViewStart.setText(sdf.format(dt));
            }
        });

        btnEnd.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Date dt = new Date(System.currentTimeMillis());
                txtViewEnd.setText(sdf.format(dt));

            }
        });

How can I handle this issue as well as in case of Day Light Saving as well

Mr.Noob
  • 1,005
  • 3
  • 24
  • 58
  • Is the code that handles time change in your onCreate() or onResume() method? Also, can you post said code? – verybadalloc Jun 12 '13 at 10:01
  • What I have written is just a code to return the current Date time inside onCreate(). I will update the code in the question – Mr.Noob Jun 12 '13 at 10:08
  • Refer: https://stackoverflow.com/questions/36253913/how-to-detect-daylight-saving-time-transition-in-android – Ashish John Jul 17 '17 at 08:41

1 Answers1

0
        TimeZone timezone = TimeZone.getTimeZone(selectManulTimeZoneString);
    OR
    TimeZone timezone = TimeZone.getDefault();
String TimeZoneName = timezone.getDisplayName();
int TimeZoneOffset = timezone.getRawOffset() / (60 * 60 * 1000);
double hoursDiff = timezone.getDSTSavings() / (60 * 60 * 1000);
Log.i("AM","DayLightSaving:" + hoursDiff);
Arfan Mirza
  • 668
  • 1
  • 14
  • 24