I would like to adjust the "[% format_date( now(),'dd/MM/yyyy HH:mm:ss') %]", as it currently displays 07/12/2020 13:31:40 on the map, as I am in the UK right now. However, I would like to change the time to fit time zone that is 6 hours behind me (a South American country). Is there any way I can do this?
map_label = QgsLayoutItemLabel(layout)
map_label.setText("[% format_date( now(),'dd/MM/yyyy HH:mm:ss') %]")
map_label.setFont(QFont("Arial", 18))
map_label.adjustSizeToText()
layout.addLayoutItem(map_label)
map_label.attemptMove(QgsLayoutPoint(40, 33, QgsUnitTypes.LayoutMillimeters))
map_label.attemptResize(QgsLayoutSize(143, 120, QgsUnitTypes.LayoutMillimeters))
1 Answer 1
I did not find a function for adding hours to a date so here's a workaround expression:
format_date(make_datetime(year(now()), month(now()), day(now()), hour(now()) - 6, minute(now()), second(now())),'dd/MM/yyyy HH:mm:ss')
-
Thank you very much for your help. It works perfectly fineLiamHems– LiamHems2020年12月07日 14:30:32 +00:00Commented Dec 7, 2020 at 14:30
-
Would you also know by any chance how to add a label that contains a value within an attribute table? For example, I have a vector point and within the attribute table, I have a column called magnitude and would like to display this magnitude as a label on the map. ThanksLiamHems– LiamHems2020年12月07日 14:32:22 +00:00Commented Dec 7, 2020 at 14:32
-
If the expression has the layer context then simply use "magnitude" in the expressionLeon Powałka– Leon Powałka2020年12月07日 14:39:34 +00:00Commented Dec 7, 2020 at 14:39