Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-01-14
3
Medium Priority
?
481 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 …
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

660 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