简体   繁体   中英

How to get the full post date Blogspot

Example code:

var postdate = entry.published.$t;
var month1 = [1,2,3,4,5,6,7,8,9,10,11,12];
var month2 = ["Jan","Feb","Mar","Apr","Mey","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var d = postdate.split("-")[2].substring(0,2);
var m = postdate.split("-")[1];
var y = postdate.split("-")[0];
for(var u2=0; u2<month1.length; u2++){ if(parseInt(m)==month1[u2]){ m=month2[u2]; break;}}
var daystr = (showPostDate) ? '' + m + ' ' + d + ', ' + y + '' : "";
var item = '' + daystr + '';

The final product of the post date = Feb 17, 2013

I want to date format = Saturday, Feb 17, 2013

var daynames = ["Monday","Tuesday", ... "Sunday"];

If you need formatting. You could use the post date to create a Date object. Like so:

var d = new Date(2013,2,17);

and use the d value to create your own date: ( https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date ). See example at the bottom page of the link.

Use the following to get the day and retrieve from array:

getDay
Returns the day of the week (0-6) for the specified date according to local time.

Like so:

var day = ["Monday", "Tuesday", ....];
console.log(day[d.getDay()]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM