-1

I need date and time on action by user.

But getting device date/time will not workout because we can manually adjust our device date/time.

We can do API for that.

But I think there will be some open source API to get Date/Time by location or any other go. Please direct me. Thank You

TimeZone Conversion

try
    {
String ourDate = "2018-10-17T06:36-04:00";
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmXXX");
        formatter.setTimeZone(TimeZone.getTimeZone("EST"));
        Date value = formatter.parse(ourDate);

        SimpleDateFormat dateFormatter = new SimpleDateFormat("EE, MMM,dd,yyyy'Z'hh:mm aa");
        dateFormatter.setTimeZone(TimeZone.getDefault());
        ourDate = dateFormatter.format(value);
    }
    catch (Exception e)
    {
        ourDate = "00, 000,00,0000'Z'00:00 00";
    }
    return ourDate;
Arnold Brown
  • 1,330
  • 13
  • 28
  • You can try with this `LocationManager locMan = (LocationManager) activity.getSystemService(activity.LOCATION_SERVICE); long time = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime();` – ॐ Rakesh Kumar Oct 09 '18 at 04:44

2 Answers2

0

please check this API to get the current time

http://worldclockapi.com/api/json/est/now

to change it to current user locale you can use (Kotlin code)

 SimpleDateFormat("date_time_poattern", Locale("user_locale")).format(time_in_millisecond)

change date_time_poattern to your own pattern, change user_locale to your user locale and finally add the time in millisecond

Mohammad Rbabah
  • 456
  • 2
  • 10
0

Check out this project:

https://github.com/instacart/truetime-android

You must initialize the library on a background thread:

TrueTime.build().initialize();

After that, you can call

TrueTime.now();