change format Date in Asp mvc - asp.net

i'am looking to change my format date but i can't do this .
i want to change format date like this :
("08-04-2020 12:00:00")
Code Source:
eventAllocation.StartDate = DateTime.Parse("08-04-2020 12:00:00");
I want to put a transformation for date start
eventAllocation.StartDate = DateTime.Parse(ar.startingDateTime).ToString("dd-MM-yyyy HH:mm:ss");
i try but show me error
i want make the date like format ("08-04-2020 12:00:00")

Related

How to change the default format of DATE variables in OpenEdge Progress?

Default DATE format when displaying dates is DD/MM/YY
I want to change that to DD.MM.YYYY
This is just a simple program:
DEFINE VARIABLE daDate AS DATE NO-UNDO.
daDate = TODAY.
MESSAGE daDate.
Currently the output looks like this: 16/09/20
I tried adding FORMAT "99.99.9999" after the variable name like this: DEFINE VARIABLE daDate FORMAT "99.99.9999" AS DATE NO-UNDO. but it didn't change the output at all.
When I instead of MESSAGE use DISPLAY and then write it out with FORMAT, then it displays the correct format: DISPLAY daDate FORMAT "99.99.9999".
Am I doing something completely wrong or am I missing something?
The expression you message will be converted to character first so instead you can take control over that conversion:
MESSAGE STRING(daDate,"99.99.9999").
DEFINE VARIABLE hoy AS CHARACTER NO-UNDO.
hoy = STRING (DAY (TODAY), "99") + "."
+ STRING (MONTH (TODAY), "99") + "."
+ STRING (YEAR (TODAY)) .
Message hoy.

Format local time to custom time

I have a saved time that is in the format of this: moment().format('llll').
I want to convert that time to this format: YYYYMMDD?
I tried this:
let Time = moment().format('llll')
moment(Time, 'YYYYMMMDD')
That results in moment.invalid(/* 2019年7月4日星期四 16:03 */)
Anyone an idea on how to do it?
moment().format('llll') gives you a formatted string.
To create a moment object with a formatted string, you should also provide the string format.
let Time = moment().format('llll')
moment(Time, 'llll')
After that, you can easily format moment object as string
moment(Time, 'llll').format('YYYYMMMDD')

date-fns equal to moment(date).format('L')?

If I use momentjs like moment(date).format('L') it will format date according to the input locale. For example for US will output 10/31/2018.
How can I do the same using date-fns? If I use format(date, [format], [options]) it will always format date based on the input [format] no matter the locale passed in [options]?
With date fns, you can use Long localized date
https://date-fns.org/docs/format
For example, equivalent of moment(date).format('L') should be format(new Date(), 'P')

Converting time format in simpleWeather.js

I want to convert the time from the standard 12-hour reading to the 24-hour one in simpleWeather. When I try to do it, it returns the time in the Unix epoch format.
$(function sunset(){
var sunset=
$.simpleWeather({
location:'Dalol,Afar',
woeid:'',
units:'f',
success:function(weather){
var Sunset= moment(weather.sunset, "HH:mm:ss");
html='Sunset: '+Sunset;
$('#sunset').html(html);
}
});
});
I had contacted the developer on how to do convert it using moment.js, but he didn't say much more than that. How can the code be corrected to display the desired format?
You need to first parse and then format the weather.sunset with the right formatting:
var sunset = moment(weather.sunset, ["h:mm A"]).format("HH:mm");
simpleWeather.js returns the sunset as "5:31 pm" so the corresponding moment format to parse this date is h:mm A, where the A captures the pm/am. To format it in the 24-hour notation, format("HH:mm") will do the job.

moment.js format date as iso 8601 without dashes?

How do I format a date as iso 8601 using moment.js but without the dashes and colons and setting the time to 0 e.g. if I have a date like this:
2016-10-08T09:00:00Z
How do I format as :
20161008T000000Z
Doing moment(date).toISOString() gives 2016-10-08T09:00:00.000Z which is not what I want.
You can simply parse your input into a moment object and use startOf to set time to 00:00:00. Then you can use format method to get a string in your custom format.
Here there is a working example using a string input, you can use the same code also if your input is a javascript Date object.
// Input date as string
var s = '2016-10-08T09:00:00Z';
// Reset time part
// var m = moment(s).startOf('day'); // no UTC
var m = moment.utc(s).startOf('day'); // UTC mode
// Format using custom format
console.log(m.format('YYYYMMDD[T]HHmmss[Z]'));
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>

Resources