The fromMicrosecondsSinceEpoch function of DateTime class is not working properly

From @disburden on May 29, 2018 10:30

  DateTime dd = new DateTime.fromMicrosecondsSinceEpoch(1527310817);
  print("date:$dd");

No matter how the parameters change, the displayed results are always the same
flutter: date:1970-01-01 08:25:17.310817
flutter: date:1970-01-01 08:25:17.310817

(dart 2.0)

Copied from original issue: dart-archive/dart_enhancement_proposals#49

Author: Fantashit

1 thought on “The fromMicrosecondsSinceEpoch function of DateTime class is not working properly

  1. hi there, it seems that is not working again.
    DateTime.fromMicrosecondsSinceEpoch(1589849381, isUtc: true)
    or
    DateTime.fromMillisecondsSinceEpoch(1589849381, isUtc: true)
    even if isUtc is true or false
    always returning 1970-01-18…..

    UPDATED:
    got it working by multiplying by 1000
    DateTime.fromMillisecondsSinceEpoch(1589849381*1000, isUtc: true)
    should it work this way?
    thanks in advance.

    environment:
    sdk: “>=2.6.0 <3.0.0”

    `# Generated by pub

    See https://dart.dev/tools/pub/glossary#lockfile

    packages:
    archive:
    dependency: transitive
    description:
    name: archive
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.0.13”
    args:
    dependency: transitive
    description:
    name: args
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.6.0”
    async:
    dependency: transitive
    description:
    name: async
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.4.1”
    bloc:
    dependency: transitive
    description:
    name: bloc
    url: “https://pub.dartlang.org
    source: hosted
    version: “3.0.0”
    boolean_selector:
    dependency: transitive
    description:
    name: boolean_selector
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.0.0”
    cached_network_image:
    dependency: “direct main”
    description:
    name: cached_network_image
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.2.0+1”
    charcode:
    dependency: transitive
    description:
    name: charcode
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.3”
    clock:
    dependency: transitive
    description:
    name: clock
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.1”
    cloud_firestore:
    dependency: “direct main”
    description:
    name: cloud_firestore
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.13.5”
    cloud_firestore_platform_interface:
    dependency: transitive
    description:
    name: cloud_firestore_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.0”
    cloud_firestore_web:
    dependency: transitive
    description:
    name: cloud_firestore_web
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.1+2”
    collection:
    dependency: transitive
    description:
    name: collection
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.14.12”
    convert:
    dependency: transitive
    description:
    name: convert
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.1.1”
    crypto:
    dependency: transitive
    description:
    name: crypto
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.1.4”
    cupertino_icons:
    dependency: “direct main”
    description:
    name: cupertino_icons
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.3”
    equatable:
    dependency: “direct main”
    description:
    name: equatable
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.1”
    file:
    dependency: transitive
    description:
    name: file
    url: “https://pub.dartlang.org
    source: hosted
    version: “5.1.0”
    firebase:
    dependency: transitive
    description:
    name: firebase
    url: “https://pub.dartlang.org
    source: hosted
    version: “7.3.0”
    firebase_admob:
    dependency: “direct main”
    description:
    name: firebase_admob
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.9.3+2”
    firebase_auth:
    dependency: “direct main”
    description:
    name: firebase_auth
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.16.0”
    firebase_auth_platform_interface:
    dependency: transitive
    description:
    name: firebase_auth_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.7”
    firebase_auth_web:
    dependency: transitive
    description:
    name: firebase_auth_web
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.2”
    firebase_core:
    dependency: transitive
    description:
    name: firebase_core
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.4.4+3”
    firebase_core_platform_interface:
    dependency: transitive
    description:
    name: firebase_core_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.4”
    firebase_core_web:
    dependency: transitive
    description:
    name: firebase_core_web
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.1+2”
    flutter:
    dependency: “direct main”
    description: flutter
    source: sdk
    version: “0.0.0”
    flutter_bloc:
    dependency: “direct main”
    description:
    name: flutter_bloc
    url: “https://pub.dartlang.org
    source: hosted
    version: “3.2.0”
    flutter_cache_manager:
    dependency: transitive
    description:
    name: flutter_cache_manager
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.2.2”
    flutter_facebook_login:
    dependency: “direct main”
    description:
    name: flutter_facebook_login
    url: “https://pub.dartlang.org
    source: hosted
    version: “3.0.0”
    flutter_native_admob:
    dependency: “direct main”
    description:
    name: flutter_native_admob
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.1.0”
    flutter_svg:
    dependency: “direct main”
    description:
    name: flutter_svg
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.17.4”
    flutter_test:
    dependency: “direct dev”
    description: flutter
    source: sdk
    version: “0.0.0”
    flutter_web_plugins:
    dependency: transitive
    description: flutter
    source: sdk
    version: “0.0.0”
    flutter_wordpress:
    dependency: “direct main”
    description:
    name: flutter_wordpress
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.4”
    font_awesome_flutter:
    dependency: “direct main”
    description:
    name: font_awesome_flutter
    url: “https://pub.dartlang.org
    source: hosted
    version: “8.8.1”
    google_sign_in:
    dependency: “direct main”
    description:
    name: google_sign_in
    url: “https://pub.dartlang.org
    source: hosted
    version: “4.4.4”
    google_sign_in_platform_interface:
    dependency: transitive
    description:
    name: google_sign_in_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.1”
    google_sign_in_web:
    dependency: transitive
    description:
    name: google_sign_in_web
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.9.1”
    html_unescape:
    dependency: “direct main”
    description:
    name: html_unescape
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.1+3”
    http:
    dependency: “direct main”
    description:
    name: http
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.12.1”
    http_parser:
    dependency: transitive
    description:
    name: http_parser
    url: “https://pub.dartlang.org
    source: hosted
    version: “3.1.4”
    image:
    dependency: transitive
    description:
    name: image
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.1.12”
    intl:
    dependency: transitive
    description:
    name: intl
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.16.1”
    js:
    dependency: transitive
    description:
    name: js
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.6.1+1”
    matcher:
    dependency: transitive
    description:
    name: matcher
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.12.6”
    meta:
    dependency: transitive
    description:
    name: meta
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.8”
    nested:
    dependency: transitive
    description:
    name: nested
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.0.4”
    path:
    dependency: transitive
    description:
    name: path
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.6.4”
    path_drawing:
    dependency: transitive
    description:
    name: path_drawing
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.4.1”
    path_parsing:
    dependency: transitive
    description:
    name: path_parsing
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.4”
    path_provider:
    dependency: transitive
    description:
    name: path_provider
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.6.7”
    path_provider_macos:
    dependency: transitive
    description:
    name: path_provider_macos
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.0.4+2”
    path_provider_platform_interface:
    dependency: transitive
    description:
    name: path_provider_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.1”
    pedantic:
    dependency: transitive
    description:
    name: pedantic
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.9.0”
    petitparser:
    dependency: transitive
    description:
    name: petitparser
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.4.0”
    platform:
    dependency: transitive
    description:
    name: platform
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.2.1”
    plugin_platform_interface:
    dependency: transitive
    description:
    name: plugin_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.2”
    provider:
    dependency: transitive
    description:
    name: provider
    url: “https://pub.dartlang.org
    source: hosted
    version: “4.1.0”
    pull_to_refresh:
    dependency: “direct main”
    description:
    name: pull_to_refresh
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.5.8”
    quiver:
    dependency: transitive
    description:
    name: quiver
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.1.3”
    rxdart:
    dependency: “direct main”
    description:
    name: rxdart
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.23.1”
    shared_preferences:
    dependency: “direct main”
    description:
    name: shared_preferences
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.5.7+1”
    shared_preferences_macos:
    dependency: transitive
    description:
    name: shared_preferences_macos
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.0.1+8”
    shared_preferences_platform_interface:
    dependency: transitive
    description:
    name: shared_preferences_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.3”
    shared_preferences_web:
    dependency: transitive
    description:
    name: shared_preferences_web
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.2+5”
    sky_engine:
    dependency: transitive
    description: flutter
    source: sdk
    version: “0.0.99”
    source_span:
    dependency: transitive
    description:
    name: source_span
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.7.0”
    sqflite:
    dependency: “direct main”
    description:
    name: sqflite
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.3.0+1”
    sqflite_common:
    dependency: transitive
    description:
    name: sqflite_common
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.1”
    stack_trace:
    dependency: transitive
    description:
    name: stack_trace
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.9.3”
    stream_channel:
    dependency: transitive
    description:
    name: stream_channel
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.0.0”
    string_scanner:
    dependency: transitive
    description:
    name: string_scanner
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.5”
    synchronized:
    dependency: transitive
    description:
    name: synchronized
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.2.0”
    term_glyph:
    dependency: transitive
    description:
    name: term_glyph
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.0”
    test_api:
    dependency: transitive
    description:
    name: test_api
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.2.15”
    timeago:
    dependency: “direct main”
    description:
    name: timeago
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.0.26”
    typed_data:
    dependency: transitive
    description:
    name: typed_data
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.1.6”
    url_launcher:
    dependency: “direct main”
    description:
    name: url_launcher
    url: “https://pub.dartlang.org
    source: hosted
    version: “5.4.7”
    url_launcher_macos:
    dependency: transitive
    description:
    name: url_launcher_macos
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.0.1+5”
    url_launcher_platform_interface:
    dependency: transitive
    description:
    name: url_launcher_platform_interface
    url: “https://pub.dartlang.org
    source: hosted
    version: “1.0.7”
    url_launcher_web:
    dependency: transitive
    description:
    name: url_launcher_web
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.1.1+5”
    uuid:
    dependency: transitive
    description:
    name: uuid
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.0.4”
    vector_math:
    dependency: transitive
    description:
    name: vector_math
    url: “https://pub.dartlang.org
    source: hosted
    version: “2.0.8”
    webview_flutter:
    dependency: “direct main”
    description:
    name: webview_flutter
    url: “https://pub.dartlang.org
    source: hosted
    version: “0.3.21”
    xml:
    dependency: transitive
    description:
    name: xml
    url: “https://pub.dartlang.org
    source: hosted
    version: “3.6.1”
    sdks:
    dart: “>=2.7.0 <3.0.0”
    flutter: “>=1.17.0 <2.0.0”
    `

Comments are closed.