title: javascript: Show remote location's AM/PM times for remote location's weather data
body: <p>What would a function look like that would return local time here, local time there, sunrise there, sunset there, the time of the weather report and the times of each of the 3hr forecasts?</p>
  
  <p>Answering my own question in separate post below.</p>
  
  <p>I am using google places api to get latitude, longitude, and utc_offset of remote location.</p>
  
  <p>I am using openweathermap api to get time (in utc format) of remote location's current weather report, sunrise, sunset, and 24 hour forecast in 3hr time increments.</p>
  
  <p>I create a javascript date() object from which I obtain my (not remote) location's utc_offset using getTimezoneOffset() function.</p>
  
  <p>I use a function (shown below) that converts a UNIX timestamp into clock hours and minutes (modified for my own use from this post on stackoverflow 5-21-2011 <a href="https://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript">Convert a Unix timestamp to time in JavaScript</a>.)</p>
  
  <p>What I need to do is this:<br>
      - get the remote utc Unix time for whatever weather information being reported (current weather, sunrise, sunset, multiple 3h forecasts)<br>
      - subtract my local utc offset to get an adjusted unix time for my current time at Greenwich.<br>
      - add the remote utc offset to get an adjusted unix time at remote location<br>
      - pass adjusted unix time to the TimeConverter function.</p>
  
  <p>Using this information, I posted the function below which uses a javascript class object to hold and return all the information needed.</p>
  
  <p>Here are my utc dates
  Timestamp from geolocation call on my local device.<br>
      timestamp:  1523646017649  (this has to be adjusted down by 1000 to match adjusted timestamps from googleplaces and openweather map)</p>
  
  <p>Timestamp from openweathermap's weather api call for remote longitude and latitude<br>
      dt:1523644200         (response.dt)<br>
      sunrise: 1523595750   (response.sys.sunrise)<br>
      sunset: 1523644821    (response.sys.sunset)<br>
      first 3h forecast: 1523653200  (response.sys.sunrise)<br></p>
  
  <p>My utcoffset from dateObj = new date();  then dateObj.getTimezoneOffset()<br>
      my utc_offset: 18000</p>
  
  <p>Remote utc_offset from googleplacesapi<br>
      utc_offset: 7200</p>
  
  <pre><code>//To get current time where I am at, I can use this call and this function&lt;br&gt;
  var myTime = timeConverter(Date.now()/1000,1);    
  // Return Result: Apr-13-2018, 2pm    
  
  function timeConverter(UNIX_timestamp,hhmmOpts){
    // based on code written by @shomrat and edited by @Chin at
    // https://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript    
    var a = new Date((UNIX_timestamp) * 1000);    
    var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];    
    var year = a.getFullYear();
    var month = months[a.getMonth()];
    var day = a.getDate();
    var hour = a.getHours();
    var amPm = ( (hour &lt; 12) ? "a" : "p" );
    if ( hour == 0) {
      hour = "12" ;
    } else if ( hour &gt; 12 ) {
      hour = (hour - 12);
    }
    var min = a.getMinutes().toString().padStart(2,"0") ;
    var time = "" ;
    if (hhmmOpts == 0) { // Apr 18, 2018, 11a    
      time += month + '-' + padLeft(day,2,'0') + '-' + year + ',&amp;nbsp;' + padLeft(hour,2,'&amp;nbsp;&amp;nbsp;') + amPm;
    } else
    if (hhmmOpts == 1) { // Apr 18, 2018, 11:27a
      time += month + '-' + padLeft(day,2,'0') + '-' + year + ',&amp;nbsp;' + hour + ":" + min + amPm;
    } else
    if (hhmmOpts == 2) { // 11p
      time += hour + ":" + min + amPm;
    }
    return time;
  }
  </code></pre>