I have a datetime filed in my models.py and another field that saves the selected timezone as well (like Asia/Tehran).
I need to append the the utc info of this timezone to my datetime object like this:
'20/4/2021 18:33:00 Gmt+4:30
How can i do that?
            Asked
            
        
        
            Active
            
        
            Viewed 464 times
        
    0
            
            
        - 
                    What code do you have so far? – liamgbs Apr 28 '21 at 15:29
 - 
                    I don't know which function i need to use to give me the "GMT+4" – Niloofar Apr 28 '21 at 15:33
 
1 Answers
1
            Use this code, replace the numbers with your specified date in your GMT+4.5 timezone.
import datetime
timezone_diff = datetime.timedelta(hours=4.5)   
GMT_timezone = datetime.timezone(timezone_diff, name="GMT")
GMT_time = datetime.datetime(2017,2,14,12,15,1,99,GMT_timezone,fold=1)
print('{0:%d}/{0:%m}/{0:%Y} {0:%H:%M:%S} {0:%Z}{0:%z}'.format(GMT_time))
        Eddy Piedad
        
- 336
 - 1
 - 8
 
- 
                    Tnx but how can create that GMT+1 according to my timezone field?this field can get different timezones – Niloofar Apr 28 '21 at 16:54
 - 
                    First, know that GMT and UTC are the same, they differ on some application. See: https://stackoverflow.com/questions/48942916/difference-between-utc-and-gmt If you plan to convert your timezone, in Tehran, you are GMT+4:30, you should make some adjustment. Let me see if I can code for you. – Eddy Piedad Apr 28 '21 at 17:15
 - 
                    
 - 
                    
 
