0

This is a way to overcomplicated script. First we get local computer time using javascript, their timezone, and GMT code using:

var timeZoneData = Intl.DateTimeFormat().resolvedOptions().timeZone;
var rightNow = new Date();
var visitorTimeZone = "GMT" + -(rightNow.getTimezoneOffset() / 60);

Then we make a GET ajax to a php server which runs a API request to pull back a webinar schedule it returns html of the next webinar which is pulled back and displayed as:

Thursday, 13 Dec 12:30 PM

I need to output it at a different format so a countdown timer can recognise it which is

Dec 13, 2018 12:30:00

I simply, for the life of me cannot work out how to do it. Here is my ajax request:

$(document).ready(function(){
    var timeZoneData = Intl.DateTimeFormat().resolvedOptions().timeZone;
    var rightNow = new Date();
    var visitorTimeZone = "GMT" + -(rightNow.getTimezoneOffset() / 60);
    $.ajax({
        type: "GET",
        url: "URLTOGETTHESTUFFWHICHPULLSBACK",
        data: 'GMT='+visitorTimeZone,
        dataType: "html",   //expect html to be returned
        async: false,
        success: function(msg){
            $('#nextWebinarForm').html(msg +' - ' + timeZoneData);
        }
    });
    $("#gmt").val(visitorTimeZone);
    document.getElementById('timezonedata').innerHTML=timeZoneData;
});

Then I do some magic vudo stuff and then I have my countdown timer: https://codepen.io/AllThingsSmitty/pen/JJavZN Which I clearly am just using someone elses pen because I don't know how to write one.

PLEASE HELP.

  • 2
    Possible duplicate of [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – Matthew Herbst Dec 13 '18 at 02:24
  • @MatthewHerbst not quite. I have googled around and taken a look through here. Everyone is doing it as if it's already in a valid date format. This is being returned as html or a string and I need to convert the string which although in a valid format is still a string to date. – Brodey Sheppard Dec 13 '18 at 02:30
  • moment.js will give you locale support https://momentjs.com/ – Nathaniel Flick Dec 13 '18 at 02:38
  • @NathanielFlick Yeah, tried moment.js still seems to not support the conversion. I'm not working off current time anymore. I've made a API request with their local time and pulled back the next schedule to their time as a string in a completely different format. – Brodey Sheppard Dec 13 '18 at 02:41
  • Is your question about how to format a date, or how to parse the date that's being returned from the API? – Barmar Dec 13 '18 at 02:51
  • Have a look at this, might help? https://stackoverflow.com/questions/20204926/return-next-localized-date-for-countdown-timer – Nathaniel Flick Dec 13 '18 at 02:54
  • `moment("Thursday, 13 Dec 12:30 PM", "dddd, D MMM H:mm A")` – Barmar Dec 13 '18 at 02:57
  • you can perform the string operations to the time which you had got it in ajax and then parse it into a date format in js. – this is yash Dec 13 '18 at 05:52

0 Answers0