Getting epoch time from calendar view in android - java

i need to get the epoch time in milliseconds of the date selected by the user from my calendar view. I use the metod calendarView.getDate() and I pass the result in my retrofit request. When I get the date back and set it as date in the view using calendarView.setDate(milliseconds) the calendar goes to dates like the '70s and if i take the number and convert it into date format using a simple python program or an online converter it gives me like if it is 2030.
I tried to set the minDate of the calendar view to 01/01/1970 but it didn't changed. I won't share my code because i just used the two methods i said.
Thank you for helping me

Related

Spring Boot 2 get client timezone [duplicate]

How to get client/request timezone in jsp?
Unfortunately this information is not passed in HTTP headers.
Usually you need cooperating JavaScript to fetch it for you.
Web is full of examples, here is one http://www.coderanch.com/t/486127/JSP/java/Query-timezone
you cannot get timezone, but you can get current time from client side.i.e. through javascript and than post back. On server side, you can convert that time to GMT/UTC. The UTC shows the TimeZone.
If you just need the local timezone in order to display local times to the user, I recommend representing all times in your service in UTC and rendering them in browsers as local times using Moment.js.
My general rule is to handle and store times in UTC everywhere except at the interface with the user, where you convert to/from local time. The advantage of UTC is that you never have to worry about daylight-saving adjustments.
Note that if you want to show the age of something (e.g. "posted 3 hours ago") you just need to compare the UTC timestamp with the current UTC time; no need to convert to local times at all.
Best solution for me is sending date/time as a string, and then parse with server's timezone to get a timestamp. Timestamps are always UTC (or supposed to be) so you will not need client's TimeZone.
For example, sending "10/07/2018 12:45" can be parsed like:
SimpleDateFormat oD = new SimpleDateFormat();
oD.applyPattern("dd/MM/yyyy HH:mm");
oD.setTimeZone(TimeZone.getDefault()); // ;)
Date oDate = oD.parse(request.getParameter("time"));
Obviously you can set your specific date/time format.

Format date in Vaadin date picker

I'm using Vaadin Date picker 3.3.0
In Java, I set locale as the below code.
datePicker.setLocale(Locale.CANADA_FRENCH);
But the date format display is YYYY-MM-dd.
How to format it to: YYYY/MM/dd ??
Thank you!
The only way right now to influence the date format of the date picker by using the Java API is to use the locale (like you do).
There is a feature request for setting a date format manually (like datePicker.setDateFormat("YYYY/MM/dd");), maybe you want to give a thumb up on that feature request so that they will implement this soon: https://github.com/vaadin/vaadin-date-picker-flow/issues/156
Also in the comments of that feature request, there is described an alternative approach on how to set a date format manually by not using the Java API, but using JavaScript. Maybe you want to give it a try: https://github.com/vaadin/vaadin-date-picker-flow/issues/156#issuecomment-603904954

android studio where does the calendar get the time from

I have an old android phone with no SIM card that I want to use to test smaller screens with my timecard app, what I'm wondering is, where does the calendar method,
For example:
Calender now = Calendar.getInstance()
get the time from? A server or does it get the time data directly from the android cellphone?
The method getInstance returns a calendar whose locale is based on system settings and whose time fields have been initialized with the current date and time.
https://developer.android.com/reference/java/util/Calendar.html

Primefaces Calendar select week instead day

I am using primefaces calendar. I want to select a week instead of selecting a day.
I found out it was possible in primefaces 2.0 to have an array of days in backbean instead of one date object. I am using version 4 and it is not possible anymore. I was thinking if i could use the week number as the pattern and use the popup calendar it will show the week number in the text field. However it worked first time i tried, but second time i want to choose a date it will only display "w". Is the anyway to make this work?
i was thinking to use a converter which convert the week number to a date because my theory is that calendar cant convert the week number to date by it self. I am not familiar using converters? I will appreciate any help.
<p:calendar value="#{bean.date}" locale="en" pattern="w">

Google App Engine - GAE will not set Default TimeZone

I have tried the following so I can get Date based on my timezone which is "Africa/Johannesburg" or GMT+2:00 but Google servers always return time using its own timezone which is 2 hours behind mine.
I have done the FF:
in appengine-web.xml I have set
<property name="user.timezone" value="Africa/Johannesburg"/>
I have also tried TimeZone.setDefault(TimeZone.getTimeZone("GMT+2:00")); before creating Date object
in the init method of my servlet, I have also tried
#Override
public void init() throws ServletException {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+2:00"));
}
But this thing won't just work. Because JDK date is not thread safe, I am using JodaTime, which works well, In fact when I do new DateTime(DateTimeZone.forID("Africa/Johannesburg")) I get correct time but for legacy issues, I have to store date in JDK date hence have to convert Joda to JDK Date by invoking .Date(), then the time is completely screwed up in wrong timezone.
Does anyone by chance know how to set this without having to subtract the hours difference.
You can't. The system timezone is not changeable. You should store all of your dates in unix time and convert them to a Date or Calendar object using your timezone. I also would not assume that GAE is always going to use the same timezone...
When you save any date in Datastore it will be saved in the timeZone you have set in your JVM, thats why before starting the app I always set it to UTC:
//To avoid difference of dates depending on where the server is located
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Nonetheless when you browse the datastore in the gcloud console it will be shown in your local timezone (probably it gets the browser timezone and adapts the response to you). But when you query it back the calendar date taken in count will be the one you used for saving it (In my case UTC).

Categories

Resources