So here is how i setup my datepicker
$('#picker').datepicker({
format: 'yyyy-mm-dd',
multidate: true
});
and then here is how i showing the result
$('#picker').on('changeDate', function(event) {
console.log( $('#picker').datepicker("getDates"));
});
here is the result from console
[Tue Jun 02 2020 00:00:00 GMT+0700 (Waktu Indonesia Barat), Wed Jun 10 2020 00:00:00 GMT+0700 (Waktu Indonesia Barat), Wed Jun 17 2020 00:00:00 GMT+0700 (Waktu Indonesia Barat)]
How can i make it to yyyy-mm-dd format ?
So here is how i fix it
$('#picker').datepicker("getFormattedDate")
maybe it will help others
Give moment.js a try. It is a very powerful tool not just only to format Date objects, but to manipulate them and make custom validations.
Related
I have this in c#:
var date = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);
and the result is like this:
date = "Tue, 27 Dec 2022 13:30:35 GMT";
I want to have this result in pre-request of postman to pass this variable as date.
But this command doesn't give me the exact result:
var date = new Date();
//result: Tue Dec 27 2022 16:26:00 GMT+0100 (Central European Standard Time)
As I'm using this date variable for encryption, it's important to have it in the special format I have in c#.
Do you have any idea how can I have this result in postman?
To display time, you can use momentjs, that's already included in postman. The cons is it doesn't support timezone, so the code would be:
const moment = require('moment')
let datetime = moment().format("ddd, DD MMM YYYY HH:mm:ss ") + "GMT"
//Wed, 28 Dec 2022 08:08:36 GMT
Using reg expression in pre-request section
var date = new Date();
// Tue Dec 27 2022 12:10:39 GMT-0500 (Eastern Standard Time)
console.log(date);
let match = /(Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d{1,2})\s+(\d{4})\s+(\d{2}|\d{1})\:(\d{2})\:(\d{2})\s([a-zA-Z]{3})/.exec(date);
// 0: "Tue Dec 27 2022 12:10:39 GMT"
// 1: "Tue"
// 2: "Dec"
// 3: "27"
// 4: "2022"
// 5: "12"
// 6: "10"
// 7: "39"
// 8: "GMT"
// newDate = "Tue, 27 Dec 2022 13:30:39 GMT";
newDate = `${match[1]}, ${match[3]} ${match[2]} ${match[4]} ${match[5]}:${match[6]}:${match[7]} ${match[8]}`
console.log(newDate);
Result in console
Tue Dec 27 2022 12:22:39 GMT-0500 (Eastern Standard Time)
Tue, 27 Dec 2022 12:22:39 GMT
Test string set in https://regex101.com/
Regular Expression
(Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d{1,2})\s+(\d{4})\s+(\d{2}|\d{1})\:(\d{2})\:(\d{2})\s([a-zA-Z]{3})
In Reg Expression Visualization https://regexper.com/
I need to extract the logs between two timestamps from a file in Unix. I basically kind of need those logs to be copied and output in a different file so that I can copy them.
Is there an efficient way to do this? The log format looks like this - The timestamp is in a separate line from the actual logs.
Tue 21 Apr 14:00:00 GMT 2020
{"items":[{"cpu.load": "0.94","total.memory": "6039.798 MB","free.memory": "4367.152 MB","used.memory": "1672.646 MB","total.physical.system.memory": "16.656 GB","total.free.physical.system.memory": "3860.197 MB","total.used.physical.system.memory": "12.796 GB","number.of.cpus": "8"}]}
Tue 21 Apr 18:00:00 GMT 2020
{"items":[{"cpu.load": "0.76","total.memory": "6039.798 MB","free.memory": "4352.656 MB","used.memory": "1687.142 MB","total.physical.system.memory": "16.656 GB","total.free.physical.system.memory": "3858.203 MB","total.used.physical.system.memory": "12.798 GB","number.of.cpus": "8"}]}
I am doing this but it only prints out the timestamp and not the actual logs
cat file.txt | awk -F, '{ if ($1>"Fri 21 Aug 14:00:00 GMT 2020" && $1<"Sat 22 Aug 18:00:00 GMT 2020") print }'
Can someone advice.
Trying to replace moment.js in my Angular application with Luxon to reduce bundle size.
I have come across a case where the two libraries produce a different output, and I am not sure why.
moment.js produces a date that is one hour ahead.
const activeToDateTimeString = '2014-08-06T13:07:04';
let foo1 = moment(activeToDateTimeString).utcOffset(-5, true);
let foo2 = DateTime.fromISO(activeToDateTimeString, {zone: 'America/New_York'}).setZone('America/New_York', { keepLocalTime: true });
let foo3 = DateTime.fromJSDate(new Date(activeToDateTimeString)).setZone('America/New_York', { keepLocalTime: true });
let foo4 = DateTime.fromISO(activeToDateTimeString).setZone('America/New_York', { keepLocalTime: true });
console.log(foo1.toDate());
console.log(foo2.toJSDate());
console.log(foo3.toJSDate());
console.log(foo4.toJSDate());
Output:
Wed Aug 06 2014 14:07:04 GMT-0400 (Eastern Daylight Time)
Wed Aug 06 2014 13:07:04 GMT-0400 (Eastern Daylight Time)
Wed Aug 06 2014 13:07:04 GMT-0400 (Eastern Daylight Time)
Wed Aug 06 2014 13:07:04 GMT-0400 (Eastern Daylight Time)
Why does moment.js produce a different output in this case?
let foo1 = moment(activeToDateTimeString).utcOffset(-4, true);
This would correct your code, but as you're moving to Luxon the daylight time changes won't effect you in the future.
Right now (19 mar 2020) New York is 4 hours behind UTC as from the 8th March 2020 it entered Eastern Daylight Time from Eastern Standard Time.
If New York was in Eastern Standard Time at the moment your code would output the same times.
i am having some trouble searching for an entity in my CosmicMind/Graph database.
Here is the code, which is pretty explanatory
//User 1
//data: 14 Febbraio 2017
//ora : 15:40
//name: Paolo
//User 2
//data: 14 Febbraio 2017
//ora : 12:40
//name: Ernesto
//User 3
//data: 13 Febbraio 2017
//ora : 16:40
//name: Paolo
/*Search Parameters*/
//dataSearch = 13 Febbraio 2017
//oraSearch = 16:40
//nameSearch = Paolo
var search = Search<Entity>(graph: graph).for(types: "Users").where(properties: (key: "data", value: dataSearch)).where(properties: (key:"ora", value: oraSearch)).where(properties: (key:"name", value: nameSearch))
//returns [User1, User3]
I am expecting from the search [User3], since the search parameters coincide with that entity, but instead, search is returning [User1, User3], like if dataSearch and oraSearch parameters are being ignored, and only the last search parameter nameSearch is being used for searching.
What am i doing wrong?
You have too many where statements. They are replacing themselves with each successive statement.
this:
.where(properties: (key: "data", value: dataSearch)).where(properties: (key:"ora", value: oraSearch)).where(properties: (key:"name", value: nameSearch)
should be:
.where(properties: (key: "data", value: dataSearch), (key:"ora", value: oraSearch), (key:"name", value: nameSearch))
or shorthand:
.where(properties: ("data", dataSearch), ("ora", oraSearch), ("name", nameSearch))
That's it :)
EDIT: I "solved" using another parameter for retrieving the records, a String type. It worked perfectly as searchingParameter, instead of Date type.Then, i did some operation on the data to isolate the correct result.
Maybe my xcode console can help you, but first i show you my code:
let search = Search<Entity>(graph: DataManager.shared.graph).for(types: DataManager.shared.entityType).where(properties: (key: "data", value: (DataManager.shared.datasource[0][0]["data"] as! Date)))
print("The date i am searching for->",DataManager.shared.datasource[0][0]["data"]!)
for (index,res) in search.sync().enumerated(){
print("Result #\(index)->\(res["data"]!)")
}
print("Total results found->",search.sync().count)
print("But only 10 records meet the requirement, not 22")
The date i am searching for-> 2017-02-16 11:19:14 +0000
Result #0->2017-02-15 22:31:28 +0000
Result #1->2017-02-15 22:21:51 +0000
Result #2->2017-02-15 22:31:43 +0000
Result #3->2017-02-15 22:44:31 +0000
Result #4->2017-02-16 10:56:37 +0000
Result #5->2017-02-16 10:56:48 +0000
Result #6->2017-02-16 10:59:23 +0000
Result #7->2017-02-15 22:32:01 +0000
Result #8->2017-02-16 10:56:21 +0000
Result #9->2017-02-15 22:23:06 +0000
Result #10->2017-02-16 11:16:00 +0000
Result #11->2017-02-16 11:19:14 +0000
Result #12->2017-02-15 22:32:12 +0000
Result #13->2017-02-15 22:42:12 +0000
Result #14->2017-02-16 11:18:07 +0000
Result #15->2017-02-16 10:59:59 +0000
Result #16->2017-02-15 22:31:36 +0000
Result #17->2017-02-16 10:58:24 +0000
Result #18->2017-02-16 10:59:07 +0000
Result #19->2017-02-15 22:23:22 +0000
Result #20->2017-02-15 22:31:49 +0000
Result #21->2017-02-15 22:32:18 +0000
Total results found-> 22
But only 10 records meet the requirement, not 22
I can't figure out what I am doing wrong here.
Passing in a string to moment, with the format and calling .toDate().
toDate() ends up returning a time that is off by 1 hour
moment("2015-11-19T18:34:00-07:00", "YYYY-MM-DDTHH:mm:ssZ").toDate()
> Thu Nov 19 2015 17:34:00 GMT-0800 (PST)
The time should be 18:34, not 17:34. The timezone is showing -08, when it should be showing -07