Solved

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

Posted on 2015-01-14
3
448 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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…

710 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