Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-01-14
3
Medium Priority
?
497 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
  • 2
3 Comments
 
LVL 11

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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 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