我从访问数据库中提取数据,以显示在ASP.NET项目的GridView控件中.它工作正常,但我想看看我是否可以格式化正在拉动的数据.目前,任何货币都会从xx.xx截断为美元金额.日期显示mm/dd/yyyy hh/mm/ss AM/PM
我尝试将数据库本身编辑为正确的值(我将货币字段设置为"货币",将日期字段设置为"短日期",但是当我拉出该日期时,它仍然显示它们没有格式化.
编辑:对不起,不得不把代码删掉
有任何想法吗?谢谢
我有一个以毫秒为单位的日期,我将其转换为可读日期.然后我将它转换成一个字符串,这样我就可以拆分它并将其分解以使用我需要的部分.问题是当我按空间分解它时,它会自动分解每个字符,并且不会在有空格的地方将其拆分.谁能解释为什么以及我做错了什么?
这是我的代码:
var formattedDate = new Date(somedateMS);
var formattedDateSplit = formattedDate.toString();
formattedDateSplit.split(" ");
console.log(formattedDateSplit); // Mon May 18 2015 18:35:27 GMT-0400 (Eastern Daylight Time)
console.log(formattedDateSplit[0]); // M
console.log(formattedDateSplit[1]); // o
console.log(formattedDateSplit[2]); // n
console.log(formattedDateSplit[3]); // [space]
console.log(formattedDateSplit[4]); // M
console.log(formattedDateSplit[5]); // a
console.log(formattedDateSplit[6]); // y
Run Code Online (Sandbox Code Playgroud)
我怎么能把它分开以便我可以摆脱一周中的哪一天,并将2015年5月18日18:35:27分成4个单独的值?(2015年5月18日18:35:27)?
我以前做过这个,不知道为什么这次它会被角色分裂.
谢谢!
我正在尝试创建一个DIV并使用for循环将其附加到页面上的所有现有DIV.问题是当它在for循环中时,它会将新的DIV仅添加到最后找到的DIV中,而不是像FOR循环那样将它添加到每个DIV中.谁能告诉我我做错了什么?
这是我正在使用的代码:
HTML:
<div class="Id">
<div class="first">First</div>
</div>
<div class="Id">
<div class="first">First</div>
</div>
<div class="Id">
<div class="first">First</div>
</div>
<div class="Id">
<div class="first">First</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
var secondDiv, secondDivImg, selectDivContainer;
secondDivImg = document.createElement("span");
secondDivImg.className = "divImg";
secondDiv = document.createElement("div");
secondDiv.className = 'second';
secondDiv.innerHTML = "Second";
secondDiv.appendChild(secondDivImg);
selectDivContainer = document.querySelectorAll('.Id');
var idLength = document.querySelectorAll('.Id').length;
for (var i=0; i<idLength; i++) {
selectDivContainer[i].appendChild(secondDiv);
console.log(i);
console.log(selectDivContainer[i]);
}
Run Code Online (Sandbox Code Playgroud)
这是一个小提琴
我添加了几个console.log来查看它们看起来是正确的,所以我有点困惑为什么会发生这种情况.谢谢!
这个让我难过。我对条件的工作原理有所了解,但由于某种原因,此查询使我无法在清晰可见的位置找到属性。
Shelf.java
@Entity
@Table(name="BOOKSHELF")
public class Shelf {
@Id
private int shelfId;
private String shelfName;
private String shelfType;
@OneToMany(mappedBy="shelf",cascade=CascadeType.ALL)
private Set<Book> book = new HashSet<Book>(0);
//getters&setters here
Run Code Online (Sandbox Code Playgroud)
Book.java
@Entity
@Table(name="BOOKS")
public class Book {
@Id
private int bookId;
private String bookName;
private String bookState;
@ManyToOne(cascade=CascadeType.ALL)
private Shelf shelf;
//getters&setters here
Run Code Online (Sandbox Code Playgroud)
这是我的条件查询:
Criteria criteria = session.createCriteria(Book.class)
.add(Restrictions.eq("shelf.shelfId", bookLocId))
.add(Restrictions.ne("shelf.shelfType", "table"))
.add(Restrictions.ne("bookState", "requested");
Run Code Online (Sandbox Code Playgroud)
问题是中间的限制。它找不到,shelfType但是shelfId很好。感谢您的任何帮助!