admin管理员组文章数量:1434960
I have the following line of code and would like to display the time also but add a text between the date and time:
Code:
'<p class="postedon" >Posted on ' + val.date.substring(0,10)
As seen, i used a substring to only display the date but with the substring this is what is displayed on my mobile app
2013-09-01 16:20
What I want to achieve is: date + at + time
2013-09-01 at 16:20
I have the following line of code and would like to display the time also but add a text between the date and time:
Code:
'<p class="postedon" >Posted on ' + val.date.substring(0,10)
As seen, i used a substring to only display the date but with the substring this is what is displayed on my mobile app
2013-09-01 16:20
What I want to achieve is: date + at + time
2013-09-01 at 16:20
Share Improve this question edited Sep 11, 2013 at 14:30 Jakub Matczak 15.7k5 gold badges51 silver badges67 bronze badges asked Sep 11, 2013 at 14:22 Isaac BasseyIsaac Bassey 512 silver badges10 bronze badges 2- Can you clarify whether the language you're working with is java or javascript? – Jason P Commented Sep 11, 2013 at 14:27
- Java or JavaScript? Those are two different languages. – Jesper Commented Sep 11, 2013 at 14:27
2 Answers
Reset to default 2In java , better way is
String dateString = "2013-09-01 16:20";
String[] split = dateString .split(s);
System.out.println(split[0]+" at "+split[1]);
0th
element is your date string and 1th
element is time string.
If you are confused with java and javascript then
var dateString = "2013-09-01 16:20";
var split = dateString .split(s);
consol.log(split[0]+" at "+split[1]);
This was my final working code:
var dateString = val.date; // this display my blog post date e.g. "2013-09-02 15:04:50"
var split = dateString.split(' ');
output += '<div class="postxt">Posted on <span class="posval">' + split[0] + '</span> at <span class="posval">' + split[1] + '</span></div>';
Hope this helps others
本文标签: javascriptSeparate date and timeStack Overflow
版权声明:本文标题:javascript - Separate date and time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745633297a2667401.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论