Is there any way to find the requesting hour of the user irrespective of the user zone specified in the user's timezone.

Eg: I have a scenario like few users are requesting from India, where as some users are requesting from USA and some other from different timezones. So i want to restrict the users not to request after 3pm of their respective timezones.

System.now().hour() is returning the local time zone of the context user, but all the context user timezone is set to IST timezones. Is there any way to find the user's respective requesting hours.

And also anyone can please help how to restrict like 3:05pm is also after 3pm but as per my current logic(System.now().hour() > 3) will ignore this. can anyone help how to handle it along with the above scenario.

Is there any way of the similar logic where to know the weekday irrespective of the locale it will return whether it is weekday or weekend. Math.mod(monday.daysBetween(dateValue), 7)

  • you need to use BusinessHour methods Commented Jan 6, 2019 at 6:58

1 Answer 1


This code will give you the correct time according to user timezone

Datetime now = Datetime.now();
Integer offset = UserInfo.getTimezone().getOffset(now);
Datetime local = now.addSeconds(offset/1000);

you can restrict with local DateTime < 3 pm if you want the specific timezone then use

EX: Integer offset = Timezone.getTimeZone('America/New_York').getOffset(now);
  • Getting the below error: Method doesn't exist or incorrect signature: void getOffset(Datetime) from the type system.timezone
    – user5558
    Commented Jan 7, 2019 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .