We used following code to get the time
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int amPmVal = now.get(Calendar.AM_PM);
But when we change Timezone to New York in iPad it gives 1 hour less.
Can we handle this DST issue in codename one?
You set the hour but didn't set the date so DST might not be in effect. Also make sure DST is correctly set in the iPad itself and not just the hour.
Related
I'm working on React and I have to do a countdown for an event that start at a precised time at a specific timezone (say 2022/04/20 20:00:00 Paris timezone).
The date is stored in a constant in the front like so :
event:{
start: new Date('2022-04-20T20:00:00'),
end: new Date('2022-04-23T00:00:00')
}
Because the date is stored in front, it will correspond to the user local timezone.
I don't know how to do so that the date stays in paris timezone, whatever the user timezone is.
The date has to stay in a Date type because I do calculations in my Timer for the countdown.
I tried to use formatInTimeZone(date, 'Europe/Paris', 'yyyy-MM-dd HH:mm:ss zzz') from the fns-tz package but when I add the "zzz" at the end it returns an invalid date format.
Also, I noticed that some Dates format are not supported on mobile browsers (the countdown did not display on mobile because of that).
if I changed the date for '2022-04-20T19:00:00Z' would it be the job ?
I know that the Z stands for UTC, but in this case is it UTC+0 ?
I'm really not confortable with the timezones and any help would be appreciated.
I tried :
import { formatInTimeZone } from "date-fns-tz";
const start = new Date("2022-04-20T20:00:00");
const end = new Date("2022-04-23T00:00:00");
const startdate = formatInTimeZone(start,"Europe/Paris","yyyy-MM-dd HH:mm:ss");
const enddate = formatInTimeZone(end,"Europe/Paris","yyyy-MM-dd HH:mm:ss zzz");
export const dropDate = {
start: new Date(startdate),
end: new Date(enddate),
};
It seems to work but not on mobile browser.
The date format is not valid.
If you change the date to '2022-04-20T19:00:00Z', it will just factor in the GMT difference. In my case, My GMT is +0530(IST). So, it will just add 5hrs 30 mins to 19:00:00 which results in 00:30:00 of 21st April.
You can make use of dayjs library instead.
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import relativeTime from "dayjs/plugin/relativeTime";
import timezonePlugin from "dayjs/plugin/timezone";
dayjs.extend(utc);
dayjs.extend(relativeTime);
dayjs.extend(timezonePlugin);
event:{
start: dayjs("2022-04-20T23:30:00").tz('Europe/Paris'),//This will set the start time to 2022/04/20 20:00:00 Paris timezone
end: dayjs("2022-04-23T03:30:00").tz('Europe/Paris') // This will set the end time to 2022/04/23 00:00:00 Paris timezone.
}
The following code give me a java.lang.ClassCastException
long time=timePicker.getDate().getTime();
Display.getInstance().scheduleLocalNotification(notification, time, LocalNotification.REPEAT_DAY);
When i execute this code, i have the following error:
java.lang.ClassCastException - java.lang.Integer cannot be cast to java.util.Date
getTime() returns long and not int so the code is correct. What is the cause of this issue?
timePicker variable is a Picker
timePicker=new Picker();
timePicker .setType(Display.PICKER_TYPE_TIME);
Time picker doesn't return a date. You should replace your code with:
int DAY = 24 * 60 * 60000;
int time=timePicker.getTime();
Display.getInstance().scheduleLocalNotification(notification, time * 60000 + System.currrentTimeMillis() / DAY * DAY, LocalNotification.REPEAT_DAY);
In this case time will be seconds since midnight. The reason is that time picker doesn't include the date portion or the timezone. Date is very fragile/confusing when it comes to those two things so we provide a more consistent result with that approach. This is also true for duration pickers.
Creating the object for Calendar and get the time and hour and minute from it.
It gives one hour less in iPad devices for Easter Time Zone (-5:00).
is this existing, does we need to consider any code changes on creating the Calendar Object.
Calendar now = Calendar.getInstance();
Dialog.show("Time value -- 1", now.getTime().toString(),"ok",null);
now.set(Calendar.YEAR, now.get(Calendar.YEAR));
now.set(Calendar.MONTH, now.get(Calendar.MONTH));
now.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
now.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY));
now.set(Calendar.MINUTE, now.get(Calendar.MINUTE));
now.set(Calendar.DAY_OF_WEEK, now.get(Calendar.DAY_OF_WEEK));
Dialog.show("Time value -- 2", now.getTime().toString(),"ok",null);
Dialog.show("Time value -- 3", " "+now.getTimeZone(),"OK",null);
java.util.TimeZone timeZone = (java.util.TimeZone)now.getTimeZone();
Dialog.show("timeZone.useDaylightTime() -- ", timeZone.useDaylightTime()+" " ,"ok",null);
From the above code in iPad version 10.2 and for Time Zone New York, U.S.A we are getting useDaylightTime as false. whereas in simulator its value is true.
is there any way to handle DST issue on iPads in codename one.
due to calendar code, we are getting 1 hour less from actual time.
Thanks in advance.
There was a bug in the iOS VM that is now fixed. The fix should be available on the build server soon (within the next day or so). That will fix this issue.
I have an application where I need to show the date in UI like DD-MM-YYYY hh:mm:ss and again this date to timestamp.
What I have tried:
$scope.dateForUI = moment().format("DD-MM-YYYY hh:mm:ss");
Here I am getting the expected result. But I need timestamp of $scope.dateForUI as well. So I have tried
$scope.dateInTimestamp = moment().unix($scope.get_date_line);
But the console output shows the 1970 date in $scope.dateInTimestamp
My question is how I format my current date and assign it to a variable and again how to get the timestamp for this particular time.
Another thing is it possible to store the time of any timezone in to my $scope.dateForUI variable using moment.js? I need to show the IST time in every browser location.
Very new to moment.js, any help would be appreciated. Thanks in advance.
Try this:
$scope.dateInTimeStamp = moment().unix();
You can use moment-timezone to get values in fixed timezone. For example:
moment.tz("Asia/Kolkata")
Use moment.unix(Number) to get moment object from seconds since the Unix Epoch
Moreover you can use valueOf() to get milliseconds since the Unix Epoch from moment object and .unix() to get seconds.
Here a snippet to show how moment-timezone works and how you can use unix():
// basic angular mock
var $scope = {};
// Current time in India (moment object)
var momNow = moment.tz("Asia/Kolkata");
// Current time in India formatted (string)
$scope.dateForUI = momNow.format("DD-MM-YYYY HH:mm:ss");
// Current time in India as seconds from 1970 (number)
$scope.dateInTimestamp = momNow.unix();
console.log($scope.dateForUI);
console.log($scope.dateInTimestamp);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.7/moment-timezone-with-data-2010-2020.min.js"></script>
I have an UltraCalendarCombo calendar control that I need to disable a set of dates in (weekends and public holidays basically).
I iterate through the list of dates for that month and set all the corresponding dates to disabled, this makes the current month look alright, but when I click the next month button on the control and try to access a month past now + 3 or 4 it jumps back to this month.
Has anyone any idea what this control is smoking, and where I can get some?
DateTimeCollection badDates = getMeSomeBadDatesmonth, year);
foreach (DateTime date in badDates)
{
myForm.CalendarInfo.DaysOfMonth[date.Day].Enabled = false;
}
Their controls have been going downhill for some time. I want to know what they are all smoking over there. I have been using their controls since the 2004 version of Net Advantage(which I really liked), but I have given up on using them on any new development. The bloat of features has broken what functionality did work and the documentation is just horrendous :(
Sorted it, the DaysOfMonth collection applies to a specific day (by number) of all months. For example, DaysOfMonth[10] applies to the tenth of every month of the year.
So I needed to use:
Infragistics.Win.UltraWinSchedule.Day theDay = _form.ValueDateCalInfo.GetDay(date, true);
if (theDay != null) theDay.Enabled = false;