Blogger: Get Post Publish Date in JavaScript


You may want to use value of Blogger's data tag inside javascript. 
For example to get the page type of current page, you may add the following code in the template:
<script>
var pageType = '<data:pageTitle/>';
</script>

To get the publish date of current post when page type is "item" (post page).
First in Layout tab, change the Blog Posts widget to include date header like below:

Then search <b:includable id='post' var='post'> in your blogger's template, add the following code below it:

<b:includable id='post' var='post'>
<b:if cond='data:blog.pageType == "item"'>
<script>
  var dateHeader= '<data:post.dateHeader/>';
  var parts = dateHeader.split('-');
 var postDate = new Date(parts[0], parts[1]-1, parts[2]);
</script>
</b:if>

If you don't want to show date header in post, then make it invisible by adding the following css in your blogger template:
<style>
  .date-header {display: none;}
</style>

To view a complete list of Blogger's data tags, check:
How to make a blogger template : data tags - part 1
How to make a blogger template : data tags - part 2

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)