3

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))
asked Dec 7, 2020 at 13:33

1 Answer 1

2

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')

answered Dec 7, 2020 at 14:24
3
  • Thank you very much for your help. It works perfectly fine Commented 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. Thanks Commented Dec 7, 2020 at 14:32
  • If the expression has the layer context then simply use "magnitude" in the expression Commented Dec 7, 2020 at 14:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.