I have a simple XPage that is doing a partial refresh every 30 second for the demo purpose.
And randomly new Date() is returning a date that is one hour wrong.
But if I do
var d=session.createDateTime(new Date())
d.setNow()
it will return the correct datetime allways.
I've also tried printing everything on the console and the result is the same.
A database showing the problem can be found here
http://l.bitcasa.com/gco-V3cq
Anybody know what could cause this ?
Related
i want to ask about the moment of a date which is recuperated from MongoDB (creation Date)
The problem is when i work with the moment to the (creation date)which is recuperated from MongoDB, i got the current date (date of today)!!
There are two screenshots that can explain more:
(https://i.stack.imgur.com/U1EPH.png)]
(https://i.stack.imgur.com/RnUod.png)
i worked with moment js and i want other propositions if found
Thank you so much
UPDATE 2
Using the suggestions from #Bergi, I added a db execution helper to set the timezone before executing the query. This allows me to control the timezone based on the logged in user's preferences.
async function execWithTZ(sql, params, timezone) {
const client = await this.pool.connect();
await client.query<any>(`SET TIMEZONE TO '${timezone}'`, []);
return client.query<any>(sql, params);
}
const result = await execWithTZ('SELECT ...', [], 'Australia/Sydney');
QUESTION
I am trying to get Postgresql to return the day of the week of a specific date in a view. I later use this to display values by day.
The data is in a table with a column named updated which is a timestamptz field.
When running the following query using DBeaver SQL client against a PostgreSQL 12 database I get the values as I expect, with records updated on Thursday local time (just after midnight) showing up as Thursday
SELECT
count(v.id) AS count,
btrim(to_char(v.updated, 'DAY'::text)) AS day,
date_trunc('DAY'::text, v.updated) AS "updatedDay"
FROM table v
GROUP BY (to_char(v.updated, 'DAY'::text)), (date_trunc('DAY'::text, v.updated))
I put this in a view and when I query this view using node-postgres the counts are for the previous day (Wednesday), which I presume is because the database thinks it should interpret the dates in the UTC timezone.
To further prove the point, when I change the above query to use DAYTZ instead of just DAY in DBeaver I get THURSDAYAEST but in nodejs as result I get WEDNESDAYUTC
Changing all my dates to be without timezone and forcing everything to UTC on the way in is not an option for me.
How can I make node-postgres tell the database what timezone I want these dates interpreted as so that I can get the correct day?
UPDATE 1
I managed to get PostgreSQL to return the correct values to postgres node by setting the database user's timezone.
ALTER ROLE visuo_ingest SET TIMEZONE TO 'Australia/Sydney';
Now the counts for things that happened on Thursday Sydney time is counted for Thursday and not Wednesday.
Still interested in a way to do this on the connection rather than the database user level.
Still interested in a way to do this on the connection rather than the database user level.
You already found the right setting, there's no reason to alter it on a role only. You can also change the setting in a client session by running the SET command
SET TIMEZONE TO 'Australia/Sydney';
Just put that in a pgClient.query("…"); right after connecting the client.
My code is as shown below:
let time = db.sequelize.fn('NOW');
But somehow, it shows
generated time is[object Object] rather than time.
Is there anything missing to generate timestamp?
I have a nodeJS script that generates HAR files by connecting to Chrome (in debug mode)
What I'm trying to figure out is what the "timestamp" property in "Network.requestWillBeSent" object stands for. This is the sample "message.params" object:
{
requestId: '6868.1321',
frameId: '6868.2',
...
timestamp: 70683.66357,
wallTime: 1449020270.68483
}
I initially thought that timestamp is in milliseconds or seconds. So I have tried doing addition/subtraction on wallTime. All the results that I got don't make much sense. Can anybody help?
Let me know if you need additional info on this. Thanks!
UPDATE:
I think I got it figured out. It seems wallTime is in seconds, while timestamp is in microseconds. I'll go with this for now. I'll provide another update in case something new turns up.
I am using Node for fetching data from MySQL. In database, i got record like : 2013-08-13 15:44:53 . But when Node fetches from Database , it assigns value like 2013-08-19T07:54:33.000Z.
I just need to get time format as in MySQL table. Btw ( My column format is DateTime in MySQL)
In Node :
connection.query(post, function(error, results, fields) {
userSocket.emit('history :', {
'dataMode': 'history',
msg: results,
});
});
When retrieving it from the database you most likely get a Date object which is exactly what you should work with (strings are only good to display dates, but working on a string representation of a date is nothing you want to do).
If you need a certain string representation, create it based on the data stored in the Date object - or even better, get some library that adds a proper strftime-like method to its prototype.
The best choice for such a library is moment.js which allows you to do this to get the string format you want:
moment('2013-08-19T07:54:33.000Z').format('YYYY-MM-DD hh:mm:ss')
// output (in my case on a system using UTC+2 as its local timezone):
// "2013-08-19 09:54:33"
However, when sending it through a socket (which requires a string representation) it's a good idea to use the default one since you can pass it to the new Date(..) constructor on the client side and get a proper Date object again.