Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7619329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:39:38+00:00 2026-05-31T03:39:38+00:00

I was asked this question : Given a timestamp as a long value, write

  • 0

I was asked this question :

Given a timestamp as a long value, write a utility function in Java to drop the milliseconds.
For example, given an input of 1274883865399 (actual time: 20100526T14:24:25.399Z), the
function would return 1274883865000 (actual time: 2010-05-26T14:24:25.000Z)

I did this :

import java.text.*;
import java.util.*;

public class ClearMilliSeconds {
    public static void main(String[] args) {   

        long yourmilliseconds = 1274883865399L;
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
         Calendar c = Calendar.getInstance();


        Date resultdate = new Date(yourmilliseconds);
        c.set(Calendar.MILLISECOND, 0);
        resultdate.setTime(c.getTimeInMillis());
        System.out.println(sdf.format(resultdate)); 
}
}

But it did not give me the right result

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:39:40+00:00Added an answer on May 31, 2026 at 3:39 am

    If I understand you correctly there is no need to use Date / Calendar…

    long yourmilliseconds = 1274883865399L;
    long droppedMillis = 1000 * (yourmilliseconds/ 1000);    
    System.out.println(droppedMillis);
    

    1274883865000

    Or… if you wish to have date formatting…

    Calendar c = Calendar.getInstance();
    c.setTime(new Date(yourmilliseconds));
    c.set(Calendar.MILLISECOND, 0);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm.ss.SSS'Z'");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    System.out.println(sdf.format(c.getTime()));
    

    2010-05-26T14:24.25.000Z

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently in a job interview I was asked this following question (for Java): Given:
An interviewer recently asked me this question: given three boolean variables, a, b, and
This question has been asked before and no definite answer has been given. I'm
I was asked this question: You are given two lists of integers, each of
I was asked this question during phone interview. Given two strings find the minimal
Hello everybody I've recently asked this question and I've given up with the 'replace
I know this question has been asked before, but no one has given any
I have asked other AI folk this question, but I haven't really been given
Forgive me if this question has already been asked and answered. Given a class
My friend asked this question to me - You are given a table with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.