Given an unzoned DateTime and a timezone, how can I construct an instant in NodaTime?

Matthew

I have a DateTime constructed explicitly.

var myDateTime = new DateTime(2015,1,1,0,0,0);

I have a timezone obtained explicitly.

var myTimeZone = DateTimeZoneProviders.Tzdb["America/Los_Angeles"];

myDate is known to be represented in myTimeZone

How should I use this information to generate a ZonedDateTime or an Instant using NodaTime?

Matt Johnson-Pint

First, convert your DateTime to a LocalDateTime.

LocalDateTime ldt = LocalDateTime.FromDateTime(myDateTime);

Then you can assign it to a zone:

ZonedDateTime zdt = ldt.InZoneLeniently(myTimeZone);

And map it back to an instant:

Instant instant = zdt.ToInstant();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Given an unzoned DateTime and a timezone, how can I construct an instant in NodaTime?

From Dev

How can I get two midnights from given instant?

From Dev

How do I print an Instant as rfc2822 in NodaTime?

From Dev

How do I print an Instant as rfc2822 in NodaTime?

From Dev

How do I convert from MySQL DATETIME to java.time.Instant and display to user in system default timezone?

From Dev

How can I output month name in a given timezone

From Dev

Nodatime create a ZonedDateTime given a time and timezone

From Dev

Python - given a timezone-aware datetime object how do I get a timezone-naive UTC datetime object?

From Dev

How can I convert a JSON date with timezone to a SQL Server datetime?

From Dev

How can I set timezone in simple form datetime field?

From Dev

How can I batch convert timezone of DATETIME entries?

From Dev

How can I do to map "timestamp with timezone" to datetime

From Dev

How can I run python in a given timezone (change timezone from outside)?

From Dev

How can I run python in a given timezone (change timezone from outside)?

From Dev

How can I convert a string into a DateTime for a specific timezone, preserving the date exactly is it comes for that timezone?

From Dev

How can I convert a string into a DateTime for a specific timezone, preserving the date exactly is it comes for that timezone?

From Dev

How to parse an ISO string value to a NodaTime Instant?

From Dev

How should I convert a local DateTime to an Instant?

From Dev

Given local DateTime and lat/lon, how to determine a timezone and offset in NodeJs?

From Dev

How can I construct an elapsed time column from a column of pandas.datetime64?

From Dev

How can I create a DateTime object from a string that is already in a specific timezone?

From Dev

How can I parse a datetime string containing GMT in the end as its timezone?

From Dev

How can I get the timezone-aware year, month, day, hour etc. from a Python datetime?

From Dev

How can i manipulate MySQL Datetime with php, (adding hours and converting to timezone)?

From Dev

how can I get a custom timezone datetime from utc timestamp with javascript(node.js)

From Dev

How can I set an Instant to a specific time?

From Dev

Using NodaTime, how to convert an Instant to the corresponding system's ZonedDateTime?

From Dev

How Do I Convert IANA zone + datetime to UTC + Offset using NodaTime

From Dev

How can I construct this Regular Expression

Related Related

  1. 1

    Given an unzoned DateTime and a timezone, how can I construct an instant in NodaTime?

  2. 2

    How can I get two midnights from given instant?

  3. 3

    How do I print an Instant as rfc2822 in NodaTime?

  4. 4

    How do I print an Instant as rfc2822 in NodaTime?

  5. 5

    How do I convert from MySQL DATETIME to java.time.Instant and display to user in system default timezone?

  6. 6

    How can I output month name in a given timezone

  7. 7

    Nodatime create a ZonedDateTime given a time and timezone

  8. 8

    Python - given a timezone-aware datetime object how do I get a timezone-naive UTC datetime object?

  9. 9

    How can I convert a JSON date with timezone to a SQL Server datetime?

  10. 10

    How can I set timezone in simple form datetime field?

  11. 11

    How can I batch convert timezone of DATETIME entries?

  12. 12

    How can I do to map "timestamp with timezone" to datetime

  13. 13

    How can I run python in a given timezone (change timezone from outside)?

  14. 14

    How can I run python in a given timezone (change timezone from outside)?

  15. 15

    How can I convert a string into a DateTime for a specific timezone, preserving the date exactly is it comes for that timezone?

  16. 16

    How can I convert a string into a DateTime for a specific timezone, preserving the date exactly is it comes for that timezone?

  17. 17

    How to parse an ISO string value to a NodaTime Instant?

  18. 18

    How should I convert a local DateTime to an Instant?

  19. 19

    Given local DateTime and lat/lon, how to determine a timezone and offset in NodeJs?

  20. 20

    How can I construct an elapsed time column from a column of pandas.datetime64?

  21. 21

    How can I create a DateTime object from a string that is already in a specific timezone?

  22. 22

    How can I parse a datetime string containing GMT in the end as its timezone?

  23. 23

    How can I get the timezone-aware year, month, day, hour etc. from a Python datetime?

  24. 24

    How can i manipulate MySQL Datetime with php, (adding hours and converting to timezone)?

  25. 25

    how can I get a custom timezone datetime from utc timestamp with javascript(node.js)

  26. 26

    How can I set an Instant to a specific time?

  27. 27

    Using NodaTime, how to convert an Instant to the corresponding system's ZonedDateTime?

  28. 28

    How Do I Convert IANA zone + datetime to UTC + Offset using NodaTime

  29. 29

    How can I construct this Regular Expression

HotTag

Archive