Solved

How do I use jQuery to change the order and contents of an element?

Posted on 2015-01-14
3
466 Views
Last Modified: 2015-01-15
Hi all,

On my page: http://www.clarktogei.jp/category/noko%E3%81%AE%E3%83%96%E3%83%AD%E3%82%B0/
I have a repeating element div.blogpost_date-block
Within it I have a date in this format: 01 1月 2015   (day month followed by "月" year)
I would like each of these blocks to be reformatted in this way: 2015年1月1日  (year followed by "年" then month followed by "月" day followed by "日")

I don't want to change the php in the template so I would like to do this runtime using jQuery for each of the elements.

Please assist.

thanks in advance
0
Comment
Question by:badwolfff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Jeffrey Dake
ID: 40550501
You could use the jquery ui library and use the date picker date format function.

http://sharepointroot.com/2012/10/31/format-datetime-in-javascript-using-jquery/
0
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 40550506
You could try this:

$(".blogpost_date-block").each( function() {
   var str = $(this).text().replace(/(\d+)\s(\d+)月\s(\d+)/, "$3年$2月$1日");
   $(this).text(str);
});
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 40550509
I might have got that backwards. I am not familiar with chinese dates. If that doesn't work, then replace the string with "$3年$1月$2日"
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question