使用OneSignal Server REST API按东部时区发通知及纽约时区确认的技术问询
Hey there! Let's break down your questions about scheduling notifications for New York/Eastern Time Zone users clearly:
1. Can the send_after parameter achieve Eastern Time Zone scheduling?
Absolutely! The send_after parameter in OneSignal's API fully supports time zone-aware timestamps, so your approach of including GMT-0400 is valid in theory. If notifications are still being received in Indian Standard Time, here are a couple of fixes to check:
Fix JSON Syntax: Your current code has a formatting error—Java requires escaping inner quotes in JSON strings. Correct it like this:
String strJsonBody = "{\"send_after\": \"2018-03-27 02:06:00 GMT-0400\"}";Malformed JSON might cause OneSignal to ignore the
send_afterparameter entirely, defaulting to immediate delivery (which could align with your server's local Indian time).Use ISO 8601 Format for Reliability: For better parsing consistency, switch to the ISO 8601 timestamp format, which OneSignal explicitly recommends:
String strJsonBody = "{\"send_after\": \"2018-03-27T02:06:00-04:00\"}";This format eliminates ambiguity and reduces the chance of time zone misinterpretation.
When formatted correctly, send_after will reliably schedule notifications to send at the exact Eastern Time you specify.
2. New York Time Zone: GMT-04:00 or GMT-05:00?
New York follows Eastern Time (ET), which shifts between two offsets based on daylight saving time:
- Eastern Daylight Time (EDT): From the second Sunday in March to the first Sunday in November, the offset is
GMT-04:00. - Eastern Standard Time (EST): For the rest of the year, the offset is
GMT-05:00.
Your example date (2018-03-27) falls after the 2018 daylight saving start date (March 11), so New York was in EDT at that time—using GMT-0400 was correct.
Pro Tip: Avoid Hardcoding Offsets
Instead of manually updating offsets for daylight saving, use Java's java.time API to generate the correct timestamp automatically for New York:
ZoneId newYorkZone = ZoneId.of("America/New_York"); ZonedDateTime sendTime = ZonedDateTime.of(2018, 3, 27, 2, 6, 0, 0, newYorkZone); String isoTimestamp = sendTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); String strJsonBody = "{\"send_after\": \"" + isoTimestamp + "\"}";
This ensures you always use the right offset, no matter the time of year.
内容的提问来源于stack exchange,提问作者Yash Jain

