Get the time, date, city and country now

Hi
Is there a way to get the date, time, city and country of the current location?
For example,

Label 1 indicates time, Label 2 indicates date, Label 3 indicates city and country (London, England)

If there is a method it will help :slightly_smiling_face:

Thanking in advance,
RR Media

You could try this:


The label's text is set to the current date and time (it won't update :(, I'll need more code for that) and a Map will pan to your location, via a LocationSensor.

3 Likes

The Clock knows more about you than you would expect.

I had to add a JOIN to force an Instant into a Text value for the SPLIT block, otherwise it would not dock.

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

1 Like

How do you get the city and country only?
Example: Tokyo, Japan

Sorry for the inconvenience!

And I would also like to know how to make the time update on its own.
image
I did this and I want the seconds. minutes and hours to update on its own. How :man_shrugging:

Sorry to disappoint you developers, the routine posted by @ABG only provides the time zone your device is located in. The routine does NOT provide the city it is located in.
For instance, it indicates id="America/Chicago" on my devices. I am located in Texas. :cry:

The only way using Blocks to get this information is to use the LocationSensor. This tutorial

shows you a way to get the city and country of the current location.

Use a Clock to get the time and date.

Try it. :slight_smile:

2 Likes

Update time on its own? Use your blocks with a label and place them in the Clock.Timer event handler. The default interval is 1 second (1000ms); change the display interval to anything you find convenient.

Did this work for you?

1 Like

First of all, thanks for your help.
Next would it be a bother to post pictures of the relevsnt blocks>

Thanks

I suppose, IP address extension. Luckily, I was just about to post this question in the community to see if there are better options while your post showed up of nowhere :smirk:.

See the parameters.

If you want time or date, use a Weather Mate extension.

2 Likes

See this example of a digital clock
https://gallery.appinventor.mit.edu/?galleryid=02d4b962-34b4-4c5e-8fdf-f17cc87dde23

2 Likes

Thanks @Gordon_Lu,

1 Like

Maybe you can use an NTP server.

1 Like

A post was merged into an existing topic: Weather Mate :cloud: [free]

This is a Blocks only solution. It does not require an extension and gets the time, date, city and country now :slight_smile:


produces

addressTimeDate2
The Clock updates every 30 seconds. The LocationSensor initially requires about 30 to 60 seconds for the first response; later updates occur for whatever time interval is set.

The values set work in the USA, you might require some modification depending on what CurrentAddress returns in your location

Is this what you wanted to know?

1 Like

However, device time can be changed by user. :grinning:

1 Like

Yes, it is true. The original question was

and that can be done with Blocks. Extensions can also provide useful information. The method a developer uses to capture this information depends on why he/she requires the info.

2 Likes

It is a shame the Location Sensor (manager) doesn't provide a property of the time fix:

https://developer.android.com/reference/android/location/Location#getTime()

Nice little job for a student....

2 Likes

Yes but what he'll do with wrong information. :sweat_smile:
What if you replace device time with online time obtained from DateTools? That'll be better and more accurate.

1 Like

I don't expect the Clock time options to be a problem Sunny for most users. The Clock tools are more than adequate for most purposes to determine date and time. If someone has concerns the date/time returned from the Clock might be spoofed, certainly something like DateTools extension could be useful. If a developer needs to prevent someone spoofing the date and time at the device's location would be one reason to use the extension; most will not. :cry: If spoofing is a concern, the extension should be used. Most will just want to know what the date and time is where they are at the moment and those users won't adjust their device time settings. Users of an app will just want to know the date and time. :slight_smile:

Not necessarily. Now and SystemTime are fairly precise. :slight_smile:

3 Likes

Alright that's ok.
If someone wants to get correct date-time then he should always be dependent on internet.
For example, we can take WhatsApp into account. Whenever you try to misconfigure time then it warns as soon as you open the app.
If accurate time is important for functionality of your application then we shouldn't be dependent on user to provide correct time.