Quartz .NET MakeDailyTrigger - quartz.net

I am using Quartz framework, got bit confused with time generation. This is a simple code which generates daily trigger # 11:30 am. To test this out, i generated next 100 consecutive firing time using ComputeFireTimes query but time i get is wierd. May be i m missing something here.
Trigger trig = TriggerUtils.MakeDailyTrigger(11, 30);
var triggerList = TriggerUtils.ComputeFireTimes(trig, null, 100);
foreach (DateTime trigger in triggerList)
{
Console.WriteLine(trigger.ToString());
}
The output i get is
8/12/2011 3:30:00 PM
8/13/2011 3:30:00 PM
8/14/2011 3:30:00 PM
8/15/2011 3:30:00 PM
8/16/2011 3:30:00 PM
8/17/2011 3:30:00 PM
8/18/2011 3:30:00 PM
8/19/2011 3:30:00 PM
The time should have been 11:30 a.m. but it is showing 3:30 pm.

These are UTC (GMT) times, maybe your time zone is 4 hours different
from UTC? You would need to change the display to your local time zone
by calling Console.WriteLine(trigger.ToLocalTime().ToString());

Related

Storing and comparing UTC times

Say this is the current server time in UTC 2021-07-30 00:33:25 UTC, which in local time is just 2021-07-29 5:33 PM
25 hours from that time is 2021-07-31 01:33:25 UTC, which in local time is 2021-07-30 6:33 PM
The stored time being compared is saved as 2021-07-30T19:00:00+00:00, which in local time should be 2021-07-30 7:00 PM
The problem is that the stored time should be 2021-07-31T02:00:00+00:00 to equal 2021-07-30 7:00 PM,
but I'm not sure of the best approach to get that time.
Here's how I get the time being sent to my rails backend
import * as moment from 'moment-timezone';
...
const start_time = moment
.tz(
listingAvailability.listing_availability_ranges_attributes[0]
.start_time,
'YYYY-MM-DD hh:mm a'
)
.tz('America/Phoenix')
.toISOString(true)
I fixed it with
moment.utc(moment(listingAvailabilityTime).utc().local()).format();

Convert US Central Time to different time zones using moment JS

I have a Date Time(Friday, 27 October 2017 4:00:00 AM) in US Central Time zone (CDT). I want to convert this Date Time into different time zones. These are time zones i wanted to convert.
Eastern Time (EDT)
Pacific Time (PDT)
New Delhi, India (IST)
Central Europian Time (CET)
Riyadh, Saudi Arabia (AST)
Pakistan Standard Time (PKT)
Lagos, Nigeria (WAT)
Australian Standard Time (AET)
Greenwich Mean Time (GMT)
Moscow, Russia (MSK)
China Standard Time (CST)
This is how i am doing
var dateTime = moment.tz("2017-10-27 4:00:00 AM", "America/Chicago");
var IST = dateTime.tz('Asia/Calcutta').format('MMMM Do YYYY, h:mm:ss a');
console.log(IST) // October 27th 2017, 9:30:00 am
The returned Date Time is wrong. Because Indian Standard Time is 10 hours and 30 minutes ahead of Central Time.
It should be Friday, 27 October 2017 2:30 PM (IST)
Thanks!
The problem isn't with the conversion to the Indian time zone - it's the original parsing of the Chicago time.
This:
var dateTime = moment.tz("2017-10-27 4:00:00 AM", "America/Chicago");
... is treated as 4am UTC, and then converted to America/Chicago, so it ends up representing 11pm local time (on October 26th) in Chicago. You can see that by just logging the value of dateTime.
If you change the code to:
var dateTime = moment.tz("2017-10-27 04:00:00", "America/Chicago");
... then it's treated as 4am local time on the 27th, which is what I believe you expected. The result of the conversion to Asia/Calcutta is then 2:30pm as you expected.
So either change the format of your input, or specify that format. For example, this works fine too:
var dateTime = moment.tz("2017-10-27 4:00:00 AM", "YYYY-MM-DD h:mm:ss a", "America/Chicago");

moment-timezone format doesn't return the expected result

Using the tz() function from moment-timezone as follow:
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').format()
//returns '2017-10-15T13:53:43+08:00'
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').format('h:m A')
//I expect to return '9:53 PM' but it returns '1:53 PM'
Ultimately, I want to apply the fromNow() function to format the result. But when I apply it, it uses the initial timestamp and ignore the timezone applied.
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').fromNow()
//I expect to return '1 min ago' when actual time is 13:54 UTC (21:54 in HK) but it returns '8 hours ago'
What am I doing wrong here?
When you do:
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong');
You're creating a date/time that corresponds to October 15th 2017, at 1:53 PM in Hong Kong - which, in turn, corresponds to 2017-10-15T05:53:43Z (5:53 AM in UTC).
When you call the format() function:
moment.tz('2017-10-15 13:53:43','Asia/Hong_Kong').format();
It returns:
2017-10-15T13:53:43+08:00
The +08:00 part is just the UTC offset - it just tells that Hong Kong is 8 hours ahead UTC. But 2017-10-15T13:53:43+08:00 (1:53 PM in Hong Kong) is exactly the same instant as 2017-10-15T05:53:43Z (5:53 AM in UTC). That's why fromNow(), when the current time is 13:54 UTC, returns 8 hours.
If you want the date/time that corresponds to 1:53 PM in UTC, you should use the utc() function:
// October 15th 2017, 1:53 PM in UTC
moment.utc('2017-10-15 13:53:43');
Now, when the current time is 13:54 UTC, fromNow() will return 1 minute (because the date/time represents 1:53 PM in UTC).
To convert this to Hong Kong timezone, just use the tz() function:
// convert 1:53 PM UTC to Hong Kong timezone (9:53 PM)
moment.utc('2017-10-15 13:53:43').tz('Asia/Hong_Kong').format('h:m A');
This will convert 1:53 PM UTC to Hong Kong timezone (resulting in 9:53 PM):

Timezone issue in Blackberry

I am working on a project which requires me to create a Date value by setting it to a particular timezone .
I have used the following code
Date formatter1 = new Date(HttpDateParser.parse("2013-08-02 11:00:00"));
System.out.println("Date dd formatter1"+formatter1);
Result as follows:
Fri Aug 02 16:30:00 Asia/Calcutta 2013
After parsing, it is giving me time according to device time zone ...
adding 5:30 automatically if device time zone is set to India Kolkata.
I want result to be as :
Fri Aug 02 11:00:00 Asia/Calcutta 2013
I mean it should not add the offset as reference to GMT .
How could I work upon this code to set the data required to me as per the Timezone and not change it internally ?
One problem is that your original date string:
2013-08-02 11:00:00
does not include time zone information. So, it is being interpreted as a GMT time. Which then means that, displayed in Calcutta time, it will be
Fri Aug 02 16:30:00 Asia/Calcutta 2013
You want to specify that 11:00 is already in Calcutta time. To do that, use one of the formats defined in the HttpDateParser documentation:
// we make sure to specify time zone information "+05:30"!
long timeSinceEpoch = HttpDateParser.parse("2013-08-02T11:00:00+05:30");
Date date = new Date(timeSinceEpoch);
System.out.println("Date: " + date);
// use this to slightly change the date formatting ... same time zone
String pattern = "yyyy-MM-dd hh:mma";
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
String formattedDate = formatter.formatLocal(timeSinceEpoch);
System.out.println("SimpleDateFormat: " + formattedDate);
Note: that in addition to adding "+5:30" to the time string, you have to replace a space after the date with a 'T'.
This code will output:
[0.0] Date: Fri Aug 02 11:00:00 Asia/Calcutta 2013
[0.0] SimpleDateFormat: 2013-08-02 11:00am
if the device's time zone is actually set to Calcutta (Kolkata +5.5).
References
Have a look at this answer on Stack Overflow.
and maybe this one, too.

Issue with adding hours to Gregorian Calendar

I have a Grails application I created a Gregorian Calendar GMT date. The time of day was 11:00:00 PM GMT. I added 3 hours to the Gregorian Calendar object and it changed the time of day to 2:00:00 AM but it did not increment the day of the year. I had to check for the case when I add hours to the calender and if that new time should pass to a new day I had to increment the day of the year. This seems like a bug in the GregorianCalendar class but want to make sure I wasn't doing something wrong. Here are the different ways I added hours.
myCalender.add(Calender.HOUR,3)
and
myCalender.add(Calender.HOUR_OF_DAY,3)`
and
myCalender.setTimeInMillis( myCalender.getTimeInMillis() + (( (1000 * 60) * 60) * 3))`
If the begin date and time is for example 6/1/2011 11:00:00 PM GMT and I execute the above code, I would expect the new date and time to be 6/2/2011 02:00:00 AM GMT but what I got was 6/1/2011 02:00:00 AM GMT. Can someone please educate me?
Works for me:
final DateFormat format = SimpleDateFormat.getDateTimeInstance();
format.setTimeZone(DateUtils.UTC_TIME_ZONE);
final GregorianCalendar cal = new GregorianCalendar(DateUtils.UTC_TIME_ZONE);
cal.set(2011, Calendar.JUNE, 1, 23, 30, 0);
System.out.println(format.format(cal.getTime()));
cal.add(Calendar.HOUR_OF_DAY, 1);
System.out.println(format.format(cal.getTime()));
Produces:
2011-06-01 23:30:00
2011-06-02 00:30:00

Resources