I started trying to use ChatGPT instead of google for a lot of my queries. The tricky part is unlearning how to search.
For instance, I had a timestamp 2022-11-27 00:00:00.000 and wanted to display it in local string. The problem was (depending on your time zone) if you do new Date("2022-11-27 00:00:00.000").toLocaleString(), you get 11/26/2022 So I would have googled something like "pass timezone to toLocaleString", which would give me this answer [0]. But its still a lot. Instead in ChatGPT I would ask: > assume i'm in EST timezone, en-US > const d = "2022-11-27T00:00:00.000Z" > const dd = new Date(d) > How can I print out local string as Sun Nov 27 2022? To which it replied: > const d = "2022-11-27T00:00:00.000Z"; > const dd = new Date(d); > console.log(dd.toLocaleDateString("en-US", { timeZone: "America/New_York" })); But the answer was actually wrong, which is fine! Easy to test > This actually prints out 11/26/2022, 7:00:00 PM. Try again To which it replied: > The output you are getting is correct, because the date you provided is in the UTC time zone, and you are formatting it using the Eastern Time (ET) time zone... > const d = "2022-11-27T00:00:00.000Z"; > const dd = new Date(d); > console.log(dd.toLocaleString("en-US", { timeZone: "UTC" })); > // Output: "11/27/2022, 7:00:00 PM" It was pretty incredible and much better than stackoverflow as now I don't have to worry about generalizing my answer or implementing the answer to my particular use case. ChatGPT tends to be verbose but the code is clearly noted and you can often ignore the words for simple tasks. https://stackoverflow.com/questions/17478086/chrome-timezone...
Hum I'd argue that you've never learned how to search. I would have searched for "javascript date to string in specific timezone", and it would have given the following result, which is exactly what ChatGPT gives: https://stackoverflow.com/questions/10087819/convert-date-to... Actually, if you already know that you can pass a timezone to toLocaleString(), I would just go on the documentation of the function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... I'm starting to understand why there are so many people on HN claiming that "Google has started to give me bad results in recent years".
I was served maybe 60-80% spam from Google around 10 months ago (now resolved). The results you see can be significantly different from what others see.
But I don't want a specific timezone. I want it to ignore the timezone. I knew it was being thrown off by timezone but was unsure why.
This is one of dozens sometimes hundreds of questions I need answers to every day and want to minimize the friction. I don't want to have to read this unless I don't have to. Sure sometimes if its important enough or I'm curious, but the ChatGPT answer was much better for me. And I get by fine on Google otherwise function convertTZ(date, tzString) {
return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", {timeZone: tzString}));
}
// usage: Asia/Jakarta is GMT+7 convertTZ("2012/04/20 10:10:30 +0000", "Asia/Jakarta") // Tue Apr 20 2012 17:10:30 GMT+0700 (Western Indonesia Time) // Resulting value is regular Date() object const convertedDate = convertTZ("2012/04/20 10:10:30 +0000", "Asia/Jakarta") convertedDate.getHours(); // 17 // Bonus: You can also put Date object to first arg const date = new Date() convertTZ(date, "Asia/Jakarta") // current date-time in jakarta.
Comments (149) 37 threads
Show all comments
Showing thread 2 of 37
For instance, I had a timestamp 2022-11-27 00:00:00.000 and wanted to display it in local string. The problem was (depending on your time zone) if you do new Date("2022-11-27 00:00:00.000").toLocaleString(), you get 11/26/2022
So I would have googled something like "pass timezone to toLocaleString", which would give me this answer [0]. But its still a lot.
Instead in ChatGPT I would ask:
> assume i'm in EST timezone, en-US
> const d = "2022-11-27T00:00:00.000Z"
> const dd = new Date(d)
> How can I print out local string as Sun Nov 27 2022?
To which it replied:
> const d = "2022-11-27T00:00:00.000Z";
> const dd = new Date(d);
> console.log(dd.toLocaleDateString("en-US", { timeZone: "America/New_York" }));
But the answer was actually wrong, which is fine! Easy to test
> This actually prints out 11/26/2022, 7:00:00 PM. Try again
To which it replied:
> The output you are getting is correct, because the date you provided is in the UTC time zone, and you are formatting it using the Eastern Time (ET) time zone...
> const d = "2022-11-27T00:00:00.000Z";
> const dd = new Date(d);
> console.log(dd.toLocaleString("en-US", { timeZone: "UTC" }));
> // Output: "11/27/2022, 7:00:00 PM"
It was pretty incredible and much better than stackoverflow as now I don't have to worry about generalizing my answer or implementing the answer to my particular use case. ChatGPT tends to be verbose but the code is clearly noted and you can often ignore the words for simple tasks.
https://stackoverflow.com/questions/17478086/chrome-timezone...
Hum I'd argue that you've never learned how to search.
I would have searched for "javascript date to string in specific timezone", and it would have given the following result, which is exactly what ChatGPT gives: https://stackoverflow.com/questions/10087819/convert-date-to...
Actually, if you already know that you can pass a timezone to toLocaleString(), I would just go on the documentation of the function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I'm starting to understand why there are so many people on HN claiming that "Google has started to give me bad results in recent years".
I thought I was going crazy. Googles been working fine for me and I was wondering if I was just being delusional or in denial.
Sample from 10 months ago: https://i.imgur.com/Hla7cyT.jpg
Continue this thread — 6 replies
This is one of dozens sometimes hundreds of questions I need answers to every day and want to minimize the friction. I don't want to have to read this unless I don't have to. Sure sometimes if its important enough or I'm curious, but the ChatGPT answer was much better for me. And I get by fine on Google otherwise
}function convertTZ(date, tzString) {
// usage: Asia/Jakarta is GMT+7
convertTZ("2012/04/20 10:10:30 +0000", "Asia/Jakarta") // Tue Apr 20 2012 17:10:30 GMT+0700 (Western Indonesia Time)
// Resulting value is regular Date() object
const convertedDate = convertTZ("2012/04/20 10:10:30 +0000", "Asia/Jakarta")
convertedDate.getHours(); // 17
// Bonus: You can also put Date object to first arg
const date = new Date()
convertTZ(date, "Asia/Jakarta") // current date-time in jakarta.