Geoff_S
Geoff_S

Reputation: 5107

Getting proper unix timestamp with JS for facebook scheduler

I'm trying to make scheduled posts to Facebook with the PHP SDK (normal posts are working fine, just issues with scheduling)

I use dropdowns for date and time choices which I retrieve and use Moments.js to get the Unix timestamp of:

    var year = document.getElementById("selectYear").value;
    var month = document.getElementById("selectMonth").value;
    var day = document.getElementById("selectDay").value;
    var time = document.getElementById("selectTime").value;

    //in this example month is 1 day is 1 year is 2019 and time is 09:00:00

    var timeStamp = ( moment(month + '-' + day + '-' + year + '-' + time).unix() )*1000

However, when I make the call I get the Facebook PHP SDK Error #100: The specified scheduled publish time is invalid

Is this not the proper unix timestamp?

Upvotes: 0

Views: 114

Answers (1)

fjc
fjc

Reputation: 5815

A Unix time stamp counts the seconds since 1970. Javascript does the same, but in milliseconds.

You are multiplying the output of unix() by 1000, effectively creating a timestamp you can easily handle in JS, but it's not a Unix timestamp anymore. Just don't do that multiplication and you should be fine.

Upvotes: 1

Related Questions