0

I am trying this cool code to send Push Notification tomorrow at 06:00 pm.

Parse.Cloud.define("tomorrowIn18", function(request, response)
{
var query = new Parse.Query(Parse.Installation);
query.equalTo('installationId', request.installationId);

query.find({
    success: function(object){
        var inst = object[0];
        var timeZone=inst.get("timeZone").toString();

        var tomorrow =new Date();
        tomorrow.setHours(tomorrow.getHours()+24);
        tomorrow.setHours(18+parseInt(timeZone));
        tomorrow.setMinutes(0);

        Parse.Push.send({
          where: query,
          data: {
            alert: "Your Friends Await you!" 
          },
          push_time: tomorrow
        }, {
          success: function() {
            response.success("done "+tomorrow);
          },
          error: function(error) {
            response.error(error);
          }
        });
    },
    error: function(error)
    {
        response.error(error);
    }
});
});

In Push log I see - Aug 24, 00:00 am. But today is Aug 23 so result must be like this - Aug 23 06:00 pm. Where is error? What did I do wrong?

user2686299
  • 427
  • 8
  • 25

1 Answers1

1

It the time zone issue you are using parse default Utc time zone thats why you are getting this difference. This is the difference between your time zone and and parse default time zone. you can get local time by following function reference to
Convert date to another timezone in JavaScript and calculate offset as following.

var offset = new Date().getTimezoneOffset();

// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset) {

// create Date object for current location
d = new Date();

// convert to msec
// add local time zone offset
// get UTC time in msec
utc = d.getTime() + (d.getTimezoneOffset() * 60000);

// create new Date object for different city
// using supplied offset
nd = new Date(utc + (3600000*offset));

// return time as a string
return "The local time in " + city + " is " + nd.toLocaleString();

}   
Community
  • 1
  • 1
Nain
  • 1,204
  • 1
  • 12
  • 17