java calendar returns wrong hour_of_day - java.util.calendar

I have the following code:
Calendar cal= Calendar.getInstance();
cal.set(Calendar.YEAR, 1994);
cal.set(Calendar.MONTH, 03);
cal.set(Calendar.DAY_OF_MONTH,1);
cal.set(Calendar.HOUR_OF_DAY, 0);
After running it I expect:
cal.get(Calendar.HOUR_OF_DAY);
to return 0, but it returns 1.
If I use a different year/month, it works fine.
Also, setting another hour works fine, it happens only for 0.
Is there something special about April 1994? What am I missing here?
Thanks in advance.

I was using Israel TZ and due to DST transition the hour 0 on April 1st '94 does not exist.

Related

Zabbix. How use function as of parameter another function

Idea use computed property to get difference between first day of month and current.
I use formula:
last("prtMarkerSuppliesLevel.1.2") - last("prtMarkerSuppliesLevel.1.2", dayofmonth("prtMarkerSuppliesLevel.1.2") )
first part work properly, but then i use dayofmonth i get error
Cannot evaluate expression: unexpected token at ")".
What is wrong?
Answer from zabbix forum thread link
Sorry, but you can not use last function in such way, it does not
support another last function as argument
the possible workaround - just create an item with scheduled interval
:
https://www.zabbix.com/documentation...stom_intervals
interval will be something like this: Code: md1h0m0 every 1st day of
each month at 0:00 This value will be collected only once a month and
will represent your prtMarkerSuppliesLevel at the begining of the
month.
then you can use last(your.current.item) - last(scheduled.item)
Regards, Kaspars

TIMESTAMPDIFF giving unexpected result

Why is
TIMESTAMPDIFF(MONTH, '2015-12-25', '2016-02-24')
giving me 1? I would expect 2016-01-25 to be 1.
My guess is that it is actually returning something like 1.999 months and it is being simply rounded down.
How can I work around this? Or is there another function to use.
I tried PERIOD_DIFF but it does not take into account days
PERIOD_DIFF(DATE_FORMAT('2016-02-24','%Y%m'),DATE_FORMAT('2015-12-25','%Y%m'))
According to the documentation, the unit for the result is an integer, in your case it will return the whole number of months between the two dates, which is one (as the second month is not yet completed).

=WeekdayName(weekday(Today())) gives me tomorrow

I have noticed with one of my reports (SSRS), when I add weekdayname, that tomorrow's value appears.
I tested this by adding a textbox with =WeekdayName(weekday(Today())) in it. I have just run this (on a Monday) and it is saying Tuesday. So clearly it's one day out.
Does anyone know how I can go about rectifying this? I can get round it in reports by adding an expression but I suspect there's some deeper problem that I would like to rectify.
Any advice would be much appreciated.
Try specifying the first day of the week in the Weekday function to be determined by the system settings.
=WeekdayName(Weekday(Today(),FirstDayOfWeek.System))

SSRS - weekday name

any advice appreciated
I have as a column heading the expression =WeekdayName(weekday(fields!date.value))
This returns the day of the week, however, it is returning a day of the week one day in advance, eg when I put Monday's dates in the parameter it shows as 'Tuesday' in the report.
My question is can the above expression be tweaked to show the WeekdayName one day before, eg =WeekdayName(weekday(fields!date.value -1)) ? I tried this but got an error.
Thanks.
So you want to subtract one day from the your incoming date then you can use the
= DateAdd("d", -1, yourdateField)
This way you can subtract the any number of days from your date.
But did you try to see why it is giving the day of previous date. Do check the system date time or else check with the
=WeekdayName(weekday(Today()))
and see if it gives you the correct day of week for current date.
Weekday and weekdayname functions have both another optional argument for defining the starting day of the week.
Problem is the 2 functions don' t default this argument to the same value so depending on your server settings you should explicitly set the second argument of these functions.
No need to invoke a date function. As the weekday() function returns and integer you can offset the result and use the Mod operator to keep it in bounds:
=WeekdayName((weekday(fields!date.value)+5) Mod 7)+1)
The parenthesis are important to ensure the addition comes first.
Just for reference:
OP asked again because of the weekday offset and this is the correct provided solution.
=WeekdayName(weekday(Today())) gives me tomorrow
=WeekdayName(Weekday(Today(),FirstDayOfWeek.System))

how to convert json date to c# in Windows phone 8

I have to convert the json date to c# datetime format
date is 3190549620000
and it orginal date format is 24jan2014 1:17pm
how can i convert this , meanwhile i followed this blog but it not worked
First, 3190549620000 is very big, causing an overflow when using the method you linked to.
3190549620 (divided by 1000, meaning the original is in milli seconds ) works better.
Secondly, if I use the method you link to to revert to a unix timestamp, I get 1390565820.
Compare
1390565820
3190549620
If I reverse the 31 in your example to 13, I get the correct date, but incorrect time. Can you verify and confirm that your input starts with 31 and not 13?
The date issue is a simple one: it seems to be 5:30 difference. What timezone are you in? My guess would be IST, so that is simply a timezone offset issue :)
It seems that your timestamp () is in UTC.
Change the code from your link to:
private static DateTime ConvertFromUnixTimestamp(double timestamp)
{
var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return origin.AddSeconds(timestamp / 1000).ToLocalTime();
}
If I use 1390549620000 instead of your 3190549620000 as input, I get your desired result.
First you need to know what is represented by that integer. Normally in a lot of services EPOCH dates are used. These EPOCH number are seconds since 1/1/1970 0:0:0, the first date in Unix. But maybe the service you are consuming is returning you ticks, or another format of date. Can you take a look at the docs??