How to add time in seconds to UTC Date Format

35 vues (au cours des 30 derniers jours)
Zayd
Zayd le 3 Nov 2024 à 18:43
Commenté : Zayd le 4 Nov 2024 à 2:37
Let current_UTC = [2025, 12, 13, 14, 15, 16] and delta_t = 123456 seconds. How can I add delta_t to current_UTC to create an updated date and have it formatted correctly in UTC Format? Is there a built in function or do I need to code my own arithmetic?

Réponse acceptée

Shivam
Shivam le 3 Nov 2024 à 19:10
Modifié(e) : Shivam le 3 Nov 2024 à 19:11
Hi Zayd,
You can follow the below workaroud to add seconds to UTC Date format:
current_UTC = [2025, 12, 13, 14, 15, 16];
% Convert to a datetime object
current_datetime = datetime(current_UTC, 'Format', 'yyyy-MM-dd HH:mm:ss', 'TimeZone', 'UTC');
disp(current_datetime);
2025-12-13 14:15:16
% Define the time delta in seconds
delta_t = 123456;
% Add the delta to the current datetime
updated_datetime = current_datetime + seconds(delta_t);
disp(updated_datetime);
2025-12-15 00:32:52
Hope it solves the requirement.
  1 commentaire
Zayd
Zayd le 4 Nov 2024 à 2:37
This helps - Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by