我想按照从服务器收到的日期显示今天或明天。
我的日期格式为 2018年6月22日星期四10:00:00 GMT + 0530 。
我想显示明天,而不是 2018年6月22日星期四10:00:00 GMT + 0530 。
答案 0 :(得分:1)
您可以获取返回的服务器日期字符串,将其转换为Date对象,然后递增或递减日期以获取明天或昨天:
var dateServerReturned = 'Fri Jun 22 2018 10:00:00 GMT+0530'; // <-- in this example case
var dateServerToHandleTomorrow = new Date(dateServerReturned);
var dateServerToHandleYesterday = new Date(dateServerReturned);
var tomorrow = new Date(dateServerToHandleTomorrow.setDate(dateServerToHandleTomorrow.getDate()+1));
var yesterday = new Date(dateServerToHandleYesterday.setDate(dateServerToHandleYesterday.getDate()-1));
答案 1 :(得分:1)
您应该尝试使用
public ActionResult Index()
{
List<paymentmethod> listpay = new List<paymentmethod>()
{
new paymentmethod() { Id="CS",isselected = true,Name = "Cash"},
new paymentmethod() { Id="CH",isselected = false,Name = "Cheque"},
new paymentmethod() { Id="CR",isselected = false,Name = "Credit"},
new paymentmethod() { Id="BN",isselected = false,Name = "Bank"}
};
return View(listpay);
}
[HttpPost]
public string Index(IEnumerable<paymentmethod> model)
{
if (model.Count(x => x.isselected) == 0)
{
return "no any option is selected";
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append("You selected:");
foreach (paymentmethod pay in model)
{
if (pay.isselected == true)
{
sb.Append(":" + pay.Name);
}
}
return sb.ToString();
}
}
答案 2 :(得分:1)
好吧,所以尝试检查要显示的日期是今天还是明天。贝娄是我的方式,希望能有所帮助。
global.REFERENCE = moment();
global.TODAY = global.REFERENCE.clone().startOf('day');
global.YESTERDAY = global.REFERENCE.clone().subtract(1, 'days').startOf('day');
global.A_WEEK_OLD = global.REFERENCE.clone().startOf('isoweek');
export function formatDate(time) {
let momentDate = moment(time);
if (isToday(momentDate)) {
return momentDate.format('LT');
} else if (isYesterday(momentDate)) {
return getIntl().formatMessage(Messages.yesterday);
} else if (isWithinAWeek(momentDate)) {
return momentDate.format('dddd');
}
return momentDate.format('l');
}
export function isToday(momentDate) {
return momentDate.isSame(global.TODAY, 'd');
}
export function isYesterday(momentDate) {
return momentDate.isSame(global.YESTERDAY, 'd');
}
export function isWithinAWeek(momentDate) {
return momentDate.isAfter(global.A_WEEK_OLD);
}
export function isTwoWeeksOrMore(momentDate) {
return !isWithinAWeek(momentDate);
}
答案 3 :(得分:0)
如果您使用片刻,请继续。...
Math.abs(moment('pass your server date here').diff(moment(new Date()),‘days’))===0? ‘Today’: Math.abs(moment('pass your server date here').diff(moment(new Date()),‘days’))===1?'Tomorrow':'Anything else'