A simple example of the conversion of JS date and time killings

  • 2021-06-29 10:11:37
  • OfStack

1. Date format to time slaughter


function getTimestamp(time) 
 {
   return Date.parse(new Date(time));
 }

2. Time Slave to Date Format


function transformPHPTime(time) 
{
 * var date = new Date(time * 1000);
 * 
    Y = date.getFullYear() + '-';
 * M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
 * D = date.getDate() + ' ';
 * h = date.getHours() + ':';
 * m = date.getMinutes() + ':';
 * s = date.getSeconds();

 * return Y+M+D+h+m+s;
}

Related articles: