title: Flutter chat app saves a message timestamp from a device time
body: <p>I have a problem with creating same timestamp in messages that users deliver to each other.</p>
  
  <p>This is a function to send a message:</p>
  
  <pre><code>  void onSendMessage(String content, int type) {
      if (content.trim() != '') {
        textEditingController.clear();
  
        var documentReference = Firestore.instance
            .collection('messages')
            .document(groupChatId)
            .collection(groupChatId)
            .document(DateTime.now().millisecondsSinceEpoch.toString());
  
        Firestore.instance.runTransaction((transaction) async {
          await transaction.set(
            documentReference,
            {
              'idFrom': id,
              'idTo': peerId,
              'timestamp': DateTime.now().millisecondsSinceEpoch.toString(),
              'content': content,
              'type': type
            },
          );
        });
  
        cacheSet(groupChatId, content, peerNickname, peerAvatar);
        listScrollController.animateTo(0.0,
            duration: Duration(milliseconds: 300), curve: Curves.easeOut);
      } else {
        Fluttertoast.showToast(msg: 'Nothing to send');
      }
    }
  </code></pre>
  
  <p>However this <code>DateTime.now().millisecondsSinceEpoch.toString()</code> creates timestamp based on user's device. This means if userA sends a message ("hello") to userB at 10:00 but if userB replies ("world") and his device time is 9:50 it will be shown before userA's message which is false.</p>
  
  <p>Something like this:</p>
  
  <pre><code>09:50 userB - "world"
  10:00 userA - "hello"
  </code></pre>
  
  <p>Is there a general time format regardless of device time? Is it possible to set without using external API?</p>