Fri Oct 23 năm ngoái 15:24:53 GMT+0530 (India Standard Time)
Trending sort Trending sort is based off of the mặc định sorting method — by highest score — but it boosts votes that have happened recently, helping khổng lồ surface more up-to-date answers.
It falls back khổng lồ sorting by highest score if no posts are trending.Switch lớn Trending sort
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
DD/MM/YYYY format - manually
If you work with this format, then you can split the date in order lớn get day, month and year separately and then use it in another constructor - Date(year, month, day):
For more information, you can read article about Date at Mozilla Developer Network.
DD/MM/YYYY - using moment.js library
In all three examples dateObject variable contains an object of type Date, which represents a moment in time và can be further converted to any string format.
Here"s one I prepared earlier...
convertToDate(dateString) // Convert a "dd/MM/yyyy" string into a Date object let d = dateString.split("/"); let dat = new Date(d<2> + "/" + d<1> + "/" + d<0>); return dat;
I found the mặc định JS date formatting didn"t work.
So I used toLocaleString with options
const event = new Date();const options = dateStyle: "short" ;const date = event.toLocaleString("en", options);to get: DD/MM/YYYY format
See docs for more formatting options: https://www.w3schools.com/jsref/jsref_tolocalestring.asp
Parsing a string to lớn create another string that is then parsed by the built–in parser is not an efficient strategy, particularly when neither string is in a format supported by ECMA-262.
A more efficient strategy is to lớn parse the string once và give the parts directly khổng lồ the constructor, avoiding the second parse, e.g.
Date.parse only supports the formats produced by:
Parsing of any other format (including m/d/y) is implementation dependent.
function newUYDate(pDate) let dd = pDate.split("/")<0>.padStart(2, "0"); let mm = pDate.split("/")<1>.padStart(2, "0"); let yyyy = pDate.split("/")<2>.split(" ")<0>; let hh = pDate.split("/")<2>.split(" ")<1>.split(":")<0>.padStart(2, "0"); let ngươi = pDate.split("/")<2>.split(" ")<1>.split(":")<1>.padStart(2, "0"); let secs = pDate.split("/")<2>.split(" ")<1>.split(":")<2>.padStart(2, "0"); mm = (parseInt(mm) - 1).toString(); // January is 0 return new Date(yyyy, mm, dd, hh, mi, secs);
$scope.ssdate=date.toLocaleDateString();// mm/dd/yyyy format
Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
new Date() always read dd/mm/yyyy as mm/dd/yyyy(month first) hence day and month values get mixed resulting in NaN/Error
Site kiến thiết / biệu tượng công ty © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2022.8.23.42893