最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to format(ddmmyyyy) the sharepoint date field while retrieving and dispalying in textbox - Stack Overflow

programmeradmin3浏览0评论

I am reading sharepoint list item using java script and displaying content inside the content editor webpart text box, the date value in text box appears like below:

2014-09-06 00:00:00

I want to display the above date value like below:

09/06/2014  (dd/mm/yyyy)

How can I do this?

Here is my code:

document.getElementById("txtClaimDate").value=rows[0].getAttribute('ows_Claim_x0020_Date');

I am reading sharepoint list item using java script and displaying content inside the content editor webpart text box, the date value in text box appears like below:

2014-09-06 00:00:00

I want to display the above date value like below:

09/06/2014  (dd/mm/yyyy)

How can I do this?

Here is my code:

document.getElementById("txtClaimDate").value=rows[0].getAttribute('ows_Claim_x0020_Date');
Share Improve this question asked Jun 30, 2014 at 15:27 user1133737user1133737 1135 silver badges23 bronze badges 1
  • You can use Date object to create a formatted string. – Teemu Commented Jun 30, 2014 at 15:31
Add a ment  | 

3 Answers 3

Reset to default 3

You could simply transform the date with javascript Date

var selectedDate = rows[0].getAttribute('ows_Claim_x0020_Date');
var check = function(n) {return (Number(n) < 10) ? "0" + n : String(n);}; //Used for leading 0
var date = new Date(selectedDate);
var delimiter = "/";
var newDate = check(date.getMonth() + 1) + delimiter + check(date.getDate()) + delimiter + date.getFullYear();

document.getElementById("txtClaimDate").value = newDate;

You can just parse the date ponents and put them back together as you wish:

var dateString = rows[0].getAttribute('ows_Claim_x0020_Date');
var ponents = dateString.split(/\D/); // Split on non-decimal characters
document.getElementById("txtClaimDate").value =
    ponents[1] + "/" + ponents[2] + "/" + ponents[0];

It seems that SharePoint 2013 dynamically loads a script called MicrosoftAjax.js which prototypes a function called format on date objects. I'm guessing the documentation is similar to that of the C# version, but I can't say for sure.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论